Difference between revisions of "Repeat..until"

From Wiki
Jump to: navigation, search
 
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
+
{{command header|Flow Control}}
== Repeat..until ==
+
{{body|repeat { } until ( expression )|The ''repeat..until'' control structure executes the code block between the statements, and then evaluates the expression. This will make it so that [[repeat..until]] loops will always execute the code within the loop at least once. This command differs from the [[while]] command because the expression is evaluated prior to the code inside the code block, where [[while]] evaluates the expression after executing it's code block.}}
'''Flow Control'''
+
=== Synopsis ===
+
Repeat
+
until
+
=== Description ===
+
Repeat is almost like [[while]] command. Repeat executes atleast ones the code inside it. [[while]] only gets executed if extension is NOT true.
+
  
 
==== Example ====
 
==== Example ====
 
<pre>
 
<pre>
 
set %str Hello , #spc , World  
 
set %str Hello , #spc , World  
repeat  
+
repeat
 +
{
 
   set %str %str , !  
 
   set %str %str , !  
   str len %str  
+
   str len %str
 +
}
 
until #strres >= 30  
 
until #strres >= 30  
 
display ok %str  
 
display ok %str  
Line 19: Line 15:
 
</pre>
 
</pre>
  
Its important, that you understand difference between this and [[while]]. See how the code gets executed in any situation atleast ones. This can be good if you need to do something like walking to some preset spot. You must walk atleast ones but if you are not in right position you repeat it untill its it becomes true.
+
The example above illustrates the difference between a repeat..until loop and a while loop. the exclamation point will always be concatinated to the end of the %str variable, and str len will be executed once before the test for #strRes >= 30 is first evaluated.
  
=== See Also ===
+
{{1.5only}}
{|
+
=See Also=
| width=200px | [[while]] || width=200px | [[for]]
+
{{Flow Control}}
|}
+
----
+
{|
+
| Width=200px | [[Main_Page]] || Width=200px | [[Documentation]] || Width=200px | [[Documentation#Flow_Control|Flow Control]]
+
|}
+

Latest revision as of 17:59, 5 September 2007

Synopsis

repeat { } until ( expression )

Description

The repeat..until control structure executes the code block between the statements, and then evaluates the expression. This will make it so that repeat..until loops will always execute the code within the loop at least once. This command differs from the while command because the expression is evaluated prior to the code inside the code block, where while evaluates the expression after executing it's code block.

Example

set %str Hello , #spc , World 
repeat
{
  set %str %str , ! 
  str len %str
}
until #strres >= 30 
display ok %str 
halt

The example above illustrates the difference between a repeat..until loop and a while loop. the exclamation point will always be concatinated to the end of the %str variable, and str len will be executed once before the test for #strRes >= 30 is first evaluated.

Note: Only available in EasyUO 1.5+

See Also

Flow Control

  • Flow control commands allow scripts to make decisions based on the evaluation of boolean expressions.
break Jumps to first statement outside of loop
call Transfers execution to another script file
continue Jumps execution of a loop to next iteration
exit Exits a called script
for Creates a counting loop
gosub Transfers execution to the matching sub
goto Jumps to another part of the script given by a label
halt Stops the script
if Executes code based on the evaluation of an expression
pause Temporarily stops the execution of the current script
repeat..until Creates a loop that checks condition after execution
return Returns from a sub
stop Ends the script
while Creates a loop that checks condition before execution