So what exactly is "bad" about the practice of using EXIT?
It's an extra option to exit a loop, specially a FOR loop which would otherwise have to run through it's entire range or use GOTO or short circuit it's index.
What say Steve? Bad practice or not?
I don’t think so. In fact, I think it keeps things much simpler and easier to understand many times, especially with nested events.
DO
_SOURCE MyImages(Z)
FOR X = 1 TO Wide
FOR Y = 1 TO High
IF POINT(X,Y) = ColorChosen THEN EXIT DO
NEXT
NEXT
Z = Z + 1
LOOP UNTIL Z > UBOUND(MyImages)
Now, with the above, let’s say we have an array of images, and we want to search them in order to find the first one that contains a specific color. With the above, all we need is the following:
IF Z <= UBOUND(MyImages) THEN
‘We found our match. Z = the image, X/Y = the point where the color was found.
ELSE
‘That color wasn’t found.
END IF
Easy to read, follow, and understand.
Now, to do that same thing
without the EXIT...
I’ll leave that as an exercise for others, as I’m on my iPad at the moment, but I just can’t think of anyway which you’d code that would be any simpler, or more efficient, than that.