BYREF procedures and functions
A BYREF Swap procedure changes the caller's variables, and a FUNCTION returns the larger value.
SubroutinesInput and output
// BYREF parameters let a procedure change the caller's variables
PROCEDURE Swap(BYREF A : INTEGER, B : INTEGER)
DECLARE Temp : INTEGER
Temp <- A
A <- B
B <- Temp
ENDPROCEDURE
FUNCTION Max(X : INTEGER, Y : INTEGER) RETURNS INTEGER
IF X > Y
THEN
RETURN X
ENDIF
RETURN Y
ENDFUNCTION
DECLARE First : INTEGER
DECLARE Second : INTEGER
INPUT First
INPUT Second
OUTPUT "Before: ", First, " ", Second
CALL Swap(First, Second)
OUTPUT "After: ", First, " ", Second
OUTPUT "Larger: ", Max(First, Second)- Inputs
- 4, 9
- Output
Before: 4 9 After: 9 4 Larger: 9