Please enable JavaScript to view this site.

 

Navigation: Macros > Macro Language > Compiler Messages > Errors

Break and Continue must occur within a WHILE or a FOR loop

Scroll Prev Up Next More

This compiler error will occur if you put either a break or a continue statement outside of any for or while loop.

 

This message, simply put, says that you cannot break out of a loop, if you are not in a loop to start with.

 

The root cause of this error, as shown in the example below, is often that you closed a loop just a bit too early, leaving the break or continue statement on the outside.

for nCtr = 1 to 50 step 3
   // lots of code
   // ...
   // ...
   // ...
endfor
if nCtr = WeekdayOf(n_TokenDate) // oops! should be in the loop
   break
endif

Note how proper indentation of the source code would have made the error much more visible, as indenting under an endfor is weird:

for nCtr = 1 to 50 step 3
   // ...
endfor
   if nCtr = WeekdayOf(n_TokenDate) 
      break
   endif

Another possible source for this error, since you will almost always use an if block to decide if you should break or continue, is closing the if block with an endfor or endwhile instead of an endif.

for nCtr = 1 to 50 step 3
   // lots of code
   // ...
   // ...
   // ...
   if nCtr = WeekdayOf(n_TokenDate) 
      break
   endfor // oops! should be ENDIF
endfor

In that case, the present message may be accompanied by messages about mismatched ENDxxx statements. First check the messages about mismatched ENDIFs and ENDFORs before coming back to this one (which might have gone away by then).

 


Topic 108187, last updated on 18-Apr-2020