An infinite loop is a loop that executes a statement or a block of statements repeatedly, without a guarding condition to determine its end (such as the
until loops or a pre-defined set of items to loop over, like the
The syntax for an infinite loop is simply the
loop keyword, followed by the statement to be repeated:
Infinite Loops and
On its own, the infinite loop only takes a single statement to be executed for each iteration.
Given the need to eventually break out of the loop with a
exit statement, the infinite loop is almost always used in combination with a
end block statement to allow the execution of multiple statements for each iteration:
loop begin DoSomething(); DoSomethingElse(); if DoneSomethingThird then break; end;
Prematurely Exiting the Loop or a Loop Iteration
Like all loops, infinite loops can be exited prematurely using the
exit statements, and a single loop iteration can be cut short by using the
continue statement, which jumps to the next loop iteration.