From SoftMC-Wiki
Jump to: navigation, search
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.


While <condition>
       <code to execute as long as condition is true>

End While


All versions




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).


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

See Also