<< Click to Display Table of Contents >> Navigation: 3. Script Language > Loops, and repeated action > JXX-Commands: "Jump If ..." |
MiniRobotLanguage (MRL)
JOR. Conditional Jump
Jump On Repeat count
Intention
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.
As the "Loop Count" is not Variable, but an internal Register, the Loop is faster then a Conventional FOR.-Loop.
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 idea behind 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 and a Label where to jump in that case.
The general Usage is:
' Reset the Repeat Count first
RRC.
:Label
' Try something, jump away if it works
' Leave the endless loop if the number of retries is exceeded.
JOR.(number of retries)|(error-label)
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.
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.
Using the Repeat Counter value slows JOR. down to 312 Ticks.
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
JOR.P1|P2[|P3]
Parameter Explanation
P1 - number or variable containing a number which is the maximum
repeat count, before the jump is done..
P2 - Label or Variable that evaluates to a Label.
If it starts with a ":" (colon) a JSR. - Jump SubRoutine (Label) (GOSUB like)
Jump is done instead of the normal JMP. - Jump to Label (GOTO like) Jump..
P3 - (optional) must be variable, if given, is set to the Repeat-Counter Value.
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
'*************************************
'DBM.2
' The following RRC. sets the Repeat-Counter to zero
RRC.
:Labb
DBP.Repeatin 1
' The JOR. will increase the Repeat Counter
' each time its called.
JOR.3|Laba
JMP.Labb
' This is where we Jump, if the Repeat-Counter
' becomes bigger or equal to 3
:Laba
RRC.
:Labc
DBP.Repeat 2
JOR.5|Labd
JMP.Labc
:Labd
DBP.We are now here.
END.
Remarks
The RRC. builds internally a connection with the next JOR. during the Preprocessing.
You can not call RRC. for example with JSR. or JNF. because it will not make the necessary connection then.
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.
The RRC. and JOR. must be in the same file.
See also:
• JME. - Jump on More or Equal
• JLE. - Jump on Less or Equal
• JSR. - Jump SubRoutine (Label)