Loops and repeated Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Loops, and repeated action >

Loops and repeated Commands

DOL. - OOP. - Conditional Loop

Previous Top Next


MiniRobotLanguage (MRL)

 

DOL. ... OOP. Commands

DO ... LOOP, WHILE ... WEND or REPEAT ... UNTIL

 

 

Intention

 

Repeat a group of instruction in different ways. Lets start with the endless loop.

 

' Endless loop

DOL.1

...

OOP.

:exit

 

You can construct a "WHILE ... WEND" Loop.

 

' WHILE ... Loop

DOL.($$CON=1)

...

OOP.

 

This loop will be repeated WHILE ($$CON=1). In fact the formula in the condition is calculated. If the result is not zero, the loop continues running. Otherwise the loop is been left. Think of it as a "WHILE cond ... WEND" Loop.

This type of loop will never be entered, when the condition is not met. It will continue running, while the condition is not zero.

 

You can make a "REPEAT UNTIL" loop. Just write the condition at the bottom, after the OOP. Like this:

 

' REPEAT ... UNTIL - Loop

DOL.

...

OOP.($$CON=0)

 

This loop will run UNTIL the condition is met. The condition formula is been calculated. If the result is not zero, the loop execution continues. This type of loop  will run UNTIL the condition is not zero. Also its guaranteed that the loop inside is executed at least once.

 

Technically you can even combine both loops and give two exit conditions. One at the top, and one at the bottom. While this special loop does not make much sense, in real life.

 

 

 

Syntax

 

 

DOL.   ... OOP.

DOL.P1 ... OOP.

DOL. ... OOP.P1

 

 

Parameter Explanation

 

P1 - Condition of loop execution

 

' You can make an endless loop like this

DOL.1

...

OOP.

 

' Condition on Top of Loop, prevents entering of Loop if not met.

' Condition at top is WHILE ... WEND condition.

DOL.$$AAA<9

...

OOP.

 

' Condition on Bottom of Loop, guarantees

' loop is entered at least once.

' condition at bottom is "REPEAT ... UNTIL cond"

' when condition is true, loop is left!

DOL.

...

OOP.$$AAA<9

 

' You can have cond at Top and Bottom, too.

DOL.$$AAA<9

...

OOP.$$AAA<9

 

Speed in Ticks:

This command uses around 19 Ticks for a simple "DOL.1". With difficult to calculate Conditions as Parameters its a bit more.

 

 

 

Example

 

VAR.§§FIA=?pfad\myfile1.txt

VAR.§§FIB=?pfad\myfile2.txt

' This variable will be set to 1 if the file is found

: §§XIT=0

' Here is our endless loop

DOL.§§XIT=0

 PRT. I am here!

' We test for File1

 IEF.§§FIA

   : §§XIT=1

 EIF.

' We test for File2

 IEF.§§FIB

   : §§XIT=1

 EIF.

 ' We'll give the CPU a tenth of a second sleep time

 ' always do this in endless loops to save CPU time.

 ' for other running programs

 PAU.0.1

OOP.

:exit

MBX. A file appeared!

ENR.

 

 

Remarks

 

While technically not needed, its recommend that you put the condition in formula brackets (..).

 

 

Limitations:

 

There are no limitations about nesting of Loop and other constructs in any way.

The condition formula can be as complex as you want. It will be calculated using the same rules like in the CAL. - Instruction.

 

 

See also:

 

    6. Program Flow Control

    1.6.2. Looping around

    FOR. - NEX. Counting Loop

    1.5. Features and Hints