Choose 'File->New BETA Program...' Name the program 'minmax.bet'.
![[3kb 485x148 PNG] [3kb 485x148 PNG]](images/image001.png)
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 .
![[3kb 472x137 PNG] [3kb 472x137 PNG]](images/image003.png)
Then append some "empty code" by choosing 'Edit->Insert After' or by pressing Enter.
![[3kb 533x137 PNG] [3kb 533x137 PNG]](images/image005.png)
Replace the <<ImpOpt>> by myloop: (# do restart myloop #). Leave text editing mode.
![[4kb 537x140 PNG] [4kb 537x140 PNG]](images/image007.png)
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:
![[6kb 571x363 PNG] [6kb 571x363 PNG]](images/image009.png)
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:
![[9kb 417x345 PNG] [9kb 417x345 PNG]](images/image013.png)
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.
![[6kb 571x363 PNG] [6kb 571x363 PNG]](images/image015.png)
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:
![[5kb 571x274 PNG] [5kb 571x274 PNG]](images/image017.png)
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-2004 Mjølner Informatics |
[Modified: Thursday September 13th 2001 at 18:47]
|