SDA Operator’s Manual
SDA-OM-E Rev H 259
Loop While D <= Pi
Do While Y >=Z
AnyVBSCalculation
Loop
These constructions enable you to make the test before or after the calculation. If the test is made
before, the calculation might not even be done one time (if the condition for terminating were
already true). With the condition at the end, the calculation is done at least one time.
Sometimes you might want to exit the loop from somewhere inside: for example, if some kind of
problem is looming, such as the logarithm of a negative number.
For this case, you can use If . . . . Then Exit Do.
To make a pause of 10 seconds you can write:
NewTime = Timer + 10.0
Do Loop Until Timer >= NewTime
Where Timer is a clock function in the PC, which has a resolution of one second.
While . . . Wend
This is similar to Do While . . . Loop. You can write things like:
While ( (A > 2) And (C < 92677663) )
AnyVBCalculation
Wend
For . . . Next
Sometimes you know, or you think you know, the number of times that you want to do a job. For
this case a For loop is ideal, especially when you have an array of numbers to work with.
Examples:
For K = 0 To Total
HistogramBin (K) = 0
Next
Omega = TwoPi / Period
For N = 0 To Period
Y (N) = A * Sin (Omega * N)
Next
Be careful about changing the counting variable in any loop. You can do this to terminate the loop
early (but Exit For is better), but you could also prevent it from terminating at all.
For emergency exit, you can use Exit For. For example:
For K = 0 To Total
If HistogramBin(K) = 0 Then Exit For
AnyVBScripting
Next