Choose 'File->New BETA Program...' Name the program 'minmax.bet'.
The <<PrefixOpt>>
in the Form window means that you can type a super pattern here. We do not want that here, so click <<PrefixOpt>>
and press Delete.
The <<AttributeDeclOpt>>
means that you can declare attributes here. The program needs two integers: min
and max
.
Click <<AttributeDeclOpt>>
and type min,max: @integer
. Choose 'Edit->Parse Text' or press Ctrl+space to leave text editing mode.
The <<ImpOpt>>
means that you can type imperatives here. We need to initialize
min
and max
, so click <<ImpOpt>>
and type maxint->min; minint->max
. Leave text editing mode.
Now we need a loop. Mark minint->max
by holding down the mouse button from the middle of minint
to the middle of max
.
Then append some "empty code" by choosing 'Edit->Insert After' or by pressing Enter.
Replace the <<ImpOpt>>
by myloop: (# do restart myloop #)
. Leave text editing mode.
Mark myloop
as shown above and re-enter text editing mode by pressing Ctrl+space or F2. Type the code in the loop, so that it looks like this:
Is the program correct?
Find out by checking it: choose 'Compile/Run->Check Current (minmax)' or click on the Check button in the toolbar. If there are errors in the program a window showing the errors will appear:
You can click the 'Nodes' list to browse through the errors. At the bottom of the window information on the error is displayed: "i is not declared". Insert a declaration of i
by clicking on max
and inserting "empty code" (using menus or pressing Enter). Type i
and leave text editing mode.
Check the program again. This time it should work.
Now we insert a few statements that print the results of the loop. Mark all of myloop
and insert some "empty code" after the loop and add the lines shown below:
Compile and run the program from the Mjolner tool (NOT in a shell). You can interact with the program in the shell where the Mjolner tool was started.
Mjolner Tool Workshop | © 2001-2002 Mjølner Informatics |
[Modified: Thursday September 13th 2001 at 18:53]
|