Difference between revisions of "MC-Basic:WHILE ... END WHILE"
m (Miborich moved page Axystems:MC-Basic:WHILE ... END WHILE to MC-Basic:WHILE ... END WHILE: Global renaming of Axystems: namespace into (Main):) |
|||
Line 51: | Line 51: | ||
* [[MC-Basic:FOR ... NEXT|FOR ... NEXT]] | * [[MC-Basic:FOR ... NEXT|FOR ... NEXT]] | ||
− | [[Category | + | [[Category:MC-Basic:Flow Control Statements|WHILE...END WHILE]] |
}} | }} |
Revision as of 09:16, 22 May 2014
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