Sunday, June 12, 2011

3.7 Break and Continue statements

3.7 Break and Continue statements
Break
The Break procedure forces a jump out of the setof statements within a loop. Like the Goto statement, it should be used with caution.
The next statement that is executed is the one following the loop terminator. For example:

for i := 1 to 10 do
begin
...
break;
...
end;
size := 10; // breaks to here

It is important to note that the Break statement only jumps out of the current loop - not out of any nested loops above it. The Goto statement can.
Continue
Passes control to the next iteration of the enclosing iteration statement in which it appears.
The enclosing iteration assumes for, while, or repeat statements.
examples :

for i = 0 to 100 do
begin
if i MOD 2 = 0 then
Continue;
end;

No comments:

Post a Comment