Loops and repeated Commands

<< Click to Display Table of Contents >>

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

Loops and repeated Commands

RRC. - Reset Repeat-Count

Previous Top Next


MiniRobotLanguage (MRL)

 

RRC. Command

Reset Repeat Counter

 

 

Intention

 

RRC. will zero the Repeat-Count of the following JOR. - Jump On Repeat-Count in the code.

 

What is it good for?

 

This is the "RRC. / JOR.-Loop". Its specially designed for such tasks.

This is a simple and fast Integer Loop which is designed to "Jump out" after a specified number of counts.

 

This command solves the special need for a fast integer Loop where you want to jump out ofter some count.

It automates the "Repeat count" of an repeated action.

The count behind the JOR. can be a variable and can be changed during the Loop.

 

Imagine you have a special condition in your code.Something was not found or some kind of error-condition.

For example, a file was not found, or a window did not appear.

 

You decide that you want to try again, checking for the missing thing.

How often do you want to try looking for it?

That is the "Repeat count". Maybe only 3 times or 5 times. Maybe 1000 times. It's up to you.

 

Due to the fact that it is a normal Jump with a Label, it can be intermixed with other Loops in any way.

See example below. The Label must not be placed below the RRC. it can be anywhere.

 

The idea behind RRC./JOR. is:

    first make an endless loop (that endless tries whatever)

    then add an RRC. immediately before the endless-loop

finally insert an JOR. into the endless loop and hence give it a exit condition

 

The general Usage is:

 

' Reset the Repeat Count first

RRC.

  :Label

FOR.$$LOP|1|10

 ' Try something, jump away if it works

 ' Leave the endless loop if the number of retries is exceeded.

 JOR.(number of retries)|(error-label)

NEX.

JMP.Label

 

Or you can also use a endless loop instead. This is a real, working example-code:

 

RRC.

  DOL.1

  ' Try something, jump away if it works

  ' Leave the endless loop if the number of retries is exceeded.

  JOR.5|error

OOP.

ENR.

 

:error

MBX.An error happened.

END.

 

clip0902

Not using the Repeat Counter value the JOR. may use about 80 Ticks

 

Or you can use the Repeat Counter value.

 

RRC.

  :Loop  

JOR.5|out|$$LOP

DBP.$$LOP

GTO.Loop

:out

DMP.Speed

MBX.!

ENR.

 

clip0903

   Using the Repeat Counter value slows JOR. down to 312 Ticks.

 

 

Technical Details:

There are no nesting restrictions with JOR.-Loops.

 

The Repeat-counter is not a global counter.

Instead each JOR. has its own Repeat counter and must have its own RRC.

 

Therefore JOR. - Loops can be nested like all other loops.

Also you can call other JOR. - Loops in a subroutine, from a JOR.-Loop.

 

 

JOR. must be used together with its RRC. (Reset Repeat Count).

You can Repeat count a sub-program, that also repeat counts something

 

RRC.

   RRC.

   ...

   JOR.

JOR.

 

For this to work, the RRC. must come first and the JOR. must be in a following line.

In fact RRC. - JOR. is a sort of Loop-construction, that can be nested.

 

 

 

Syntax

 

RRC.

 

 

Parameter Explanation

 

No parameters are required with this command.

 

clip0896

The RRC. / JOR. - Loop is also very fast due that it does not use external Variables. It only needs 35 Cycles per Round in this example

 

 

Example

 

'*************************************

' JOR - Example

'*************************************

RRC.

 DOL.1

 ' Try something, jump away if it works

 JOR.5|error

OOP.

 

ENR.

 

:error

MBX.An error happened.

 

 

 

Remarks

 

The RRC. builds internally a connection with the next JOR.

You can not call RRC. for example with JSR. or JNF.

 

The Preprocessor will only connect the RRC with the next successive JOR.

Therefore the RRC. must be in the code above the JOR.

 

 

 

Limitations:

 

 

The Repeat counter is limited to a maximum of ~2 Billion retries.

 

 

See also:

 

    JOR. - Jump On Repeat-Count

    JIV. - Jump-If-Variable

    JIZ. - Jump-If-Zero

    JNZ. - Jump if Not zero

    JME. - Jump on More or Equal

    JLE. - Jump on Less or Equal

    JMP. - Jump to Label

    JSR. - Jump SubRoutine (Label)