Difference between revisions of "Repeat..until"

From Wiki
Jump to: navigation, search
 
(Description: fixed for clarity.)
Line 6: Line 6:
 
until
 
until
 
=== Description ===
 
=== Description ===
Repeat is almost like [[while]] command. Repeat executes atleast ones the code inside it. [[while]] only gets executed if extension is NOT true.
+
The repeat..until control structure executes the code block between the statements, and then evaluates the expression. If the expression is false, the code is executed again.
 +
Unlike [[while]] loops, repeat..until loops will always execute the code within the loop at least once.
  
 
==== Example ====
 
==== Example ====
Line 19: Line 20:
 
</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 ===
 
=== See Also ===

Revision as of 16:40, 24 August 2005

Repeat..until

Flow Control

Synopsis

Repeat until

Description

The repeat..until control structure executes the code block between the statements, and then evaluates the expression. If the expression is false, the code is executed again. Unlike while loops, repeat..until loops will always execute the code within the loop at least once.

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.

See Also

while for

Main_Page Documentation Flow Control