use of DO:LOOP and EXIT

geoff07

Senior Member
The exit command is a useful way of making the flow of code very clear, but it only works with DO or FOR loops. But it may not have occurred to you that you can in fact use it instead of downward pointing gotos, in any code that has a straight line path. Just implement a single-shot DO loop around the code:
Code:
symbol F_one = bitx
F_one = 1
Do
    if x then:... exit:endif
    if y then:... exit:endif
    if z then:... exit:endif
loop until F_one = 1
Sadly the parser expects a variable in the test so you can't use 'until 1=1' or 'until 1' as you can with other languages. But it can help make your code clearer than a string of elseifs or whatever.
 

hippy

Technical Support
Staff member
Sadly the parser expects a variable in the test so you can't use 'until 1=1' or 'until 1' as you can with other languages.
You can use 'b0=b0' and 'b0<>b0' to create true and false conditions. Even create defines using those ...

Code:
#Define TRUE  b0 =  b0
#Define FALSE b0 <> b0
Do
Loop Until TRUE
You could even create your own DO:ONCE loop structure ...

Code:
#Define Once Loop Until b0 = b0
Do
  if ... Then Exit
  ...
Once
 
Top