Loop Control (break, continue)
Loop control statements modify the normal flow of iteration within loops. The break statement immediately exits the innermost containing loop, while continue skips the remaining statements in the current iteration and proceeds to the next iteration. All loop blocks must be terminated by an end statement.
BreakStmt = "break" ;
ContinueStmt = "continue" ;
These statements provide fine-grained control over loop execution, allowing early termination or selective processing of loop iterations based on runtime conditions.
Valid Syntax:
while true do
if shouldExit then
break
end
if shouldSkip then
continue
end
ProcessItem()
end
foreach item in items do
if item.isInvalid then
continue
end
ProcessValidItem(item)
end
Notes
breakandcontinuecan only be used within loop constructsbreakexits the innermost containing loopcontinueskips to the next iteration of the innermost containing loop