Introduction to Break in C

Started by thiruvasagamani, Sep 22, 2008, 10:30 AM

Previous topic - Next topic

thiruvasagamani

Break Statement :

while( condition)
{
----
----
----
if( condition)
break;
-----
----- // the following break statements are skipped
-----
}

When break statement is executed control goes out of loop.Next statement executed after break is statement outside the loop.Statement following break are skipped along with remain iteration of loop.

NOTE:
Break can be used in for, while , do- while loops and switch

if( condition)
{
----
----
break; // error
----
----
}
we cannot use break in 'if' statement but 'if' is enclosed in a loop break can be used in 'if' as well that is
while( condition)
{
-----
-----
while( condition)
{
----
----
if( condition)
break;
----
----
}
-----
-----
-----
}

From the above , when break is used in the inner loop, control goes out of inner loop but not from outer loop.


Thiruvasakamani Karnan