Stopping a DO loop: break and breakif
- Last UpdatedOct 24, 2022
- 1 minute read
If the to option is not given, the command block within the loop will be repeated indefinitely. To stop looping, use either the break or breakif command:
do !Number
if (!Number GT 100) then
break
endif
!Result = !Result + !Number
enddo
do !Number
break if (!Number GT 100)
!Result = !Result + !Number
enddo
Any expression may be used with the breakif command, even a PML function, provided the result is BOOLEAN (as in, TRUE or FALSE).
The ( ) parentheses are optional but recommended.
The loop counter variable retains the value it had when the break from the loop occurred.