Function parameters
Contents
Function parameters#
We already learned to create functions which accept a parameter and return values#
FUNCTION GetInitial(Name : STRING) RETURNS STRING // Local variables in function DECLARE Initial : STRING Initial ← UCASE(Name[0]) RETURN Initial ENDFUNCTION OUTPUT "Enter your first name: " INPUT FirstName FirstNameInitial ← GetInitial(FirstName) OUTPUT "Your initial is: ", FirstNameInitial
Functions can accept multiple parameters#
FUNCTION GetInitial(Name : STRING, ForceUppercase : BOOLEAN) RETURNS STRING DECLARE Initial : STRING IF ForceUppercase THEN Initial ← UCASE(Name[0]) ELSE Initial ← Name[0] ENDIF RETURN Initial ENDFUNCTION OUTPUT "Enter your first name: " INPUT FirstName FirstNameInitial ← GetInitial(FirstName, FALSE) OUTPUT "Your initial is: ", FirstNameInitial
Caution
Pass the parameters in the same order they are listed in the function declaration