![]() ![]() ![]() ![]() | Table Of Contents | Index |
Procedures can accept parameters by declaring variable names on the same line as the name of the procedure.
Procedures can return variables by using the Return command. Return exits the procedure returning the parameters on the same line as the Return statement.
Example:In this example, if you were to use Factorial (5) you would get:
Procedure Factorial (X) var Y Z Y = 1 Z = 1 while Y <= X Z = Y * Z Y = Y + 1 endwhile Writeln X ' factorial is ' Z EndProc
5 factorial is 120In this example, MarxMenu draws a box and asks a question and waits for a "Yes" or "No" answer.Example:
Procedure AskYesNo (Question) var YesNo DrawBox (34 - (Length(Question) / 2)) 21 Length(Question) + 14 3 TextColor LCyan Blue UseArrows Off Write ' ',Question,' (Y/N) ' YesNo = UpperCase(ReadKey) YesNo = YesNo = 'Y' if YesNo Write 'Yes' else Write 'No' endif Wait 50 EraseTopWindow Return (YesNo) EndProc
if AskYesNo 'Do you want to continue? ' then Continue
Arrays can be passed as parameters. Parameters are passed by value not by reference. This means that any changes to the passed parameter do not affect the original value.
You can copy an array by assigning it equal to another array.
Example:This creates Array1 with a copy of all the elements of Array2. The previous contents of Array1 are overwritten.
Array1 = Array2
![]() ![]() ![]() ![]() | Table Of Contents | Index |
|