Pages

Saturday, February 27, 2010

THE break STATEMENT

Introduction
Just like the switch statement, break is used to break any type of loop. Breaking a loop means terminating it. A break terminates the loop in which the loop body is written.

Program/Example
For example,

i = 0;
while (1)
{
i = i + 1;
printf(" the value of i is %d\n");
if (i>5) break;
}

Explanation
The while (1) here means the while condition is always true.

When i reaches 6, the if condition becomes true and break is executed, which terminates the loop.

No comments:

Post a Comment