MC-Basic:WHILE ... END WHILE

From SoftMC-Wiki
Revision as of 16:38, 2 May 2017 by Chi (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

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

See Also