Difference between revisions of "MC-Basic:WHILE ... END WHILE"
(Created page with '{{MC-Basic |SHORT FORM= |SYNTAX= While ''<condition><br> <nowiki><code to execute as long as condition is true></nowiki>''<br> End While |AVAILABILITY= All vers…') |
m |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Languages|MC-Basic:WHILE_..._END_WHILE}} | ||
{{MC-Basic | {{MC-Basic | ||
|SHORT FORM= | |SHORT FORM= | ||
Line 48: | Line 49: | ||
|SEE ALSO= | |SEE ALSO= | ||
− | * [[ | + | * [[MC-Basic:DO ... LOOP|DO ... LOOP]] |
− | * [[ | + | * [[MC-Basic:FOR ... NEXT|FOR ... NEXT]] |
+ | [[Category:MC-Basic:Flow Control Statements|WHILE...END WHILE]] | ||
}} | }} |
Latest revision as of 16:38, 2 May 2017
Language: | English • 中文(简体) |
---|
While and End While keywords delimit a WHILE loop. While loops are used to execute a section of code for as long as a specified condition remains true. The condition is evaluated before any statements in the construct are executed and consequently, the body statements may never be executed. Statements are optional. If none are included, the WHILE….End WHILE acts as a delay. You can have any number of statements to be executed.
All looping constructs (FOR, WHILE, DO) use the CPU as long as a task of higher priority is not interrupting them. The condition is evaluated as frequently as allowed by the speed of the CPU. Sometimes a WHILE loop may be waiting on a condition that does not require frequent checking. In such instances, it is advisable to insert a SLEEP command into the loop to enable other tasks (perhaps lower priority tasks) to use the CPU.
Syntax
While <condition>
<code to execute as long as condition is true>
End While
Availability
All versions
Scope
Task
Limitations
Do not use WHILE…END WHILE in Config.prg. The While keyword must be matched with the End While keyword within each program block (PROGRAM…END PROGRAM, SUB…END SUB, and ONEVENT...END ONEVENT).
Examples
While x_axis.IsMoving = 1 ‘wait for profiler to finish
sleep 20
End While
While A2.VelocityFeedback < 1000
Print "Axis 2 Velocity Feedback still under 1000"
End While