Friday 30 August 2013

The “ break ” Statement | C Programming Language Tutorial pdf



The “ break ” Statement:

=> A break statement terminates the execution of the loop and the control is transferred to the statement immediately following the loop.
=> i.e., the break statement is used to terminate loops or to exit from a switch.
=> It can be used within a for, while, do-while, or switch statement.
=> The break statement is written simply as break;
Example:
switch (choice = = toupper(getchar( ))
{
case 'R': printf(“Red”);
break;
case 'W': printf(“White”);
break;
case 'B': printf(“Blue”);
break;
default: printf(“Error”);
}
=> Notice that each group of statements ends with a break statement, (in order) to transfer control out of the switch statement.
=> The last group does not require a break statement; since control will automatically be transferred out of the switch statement after the last group has been executed.

0 comments:

Post a Comment

 

C Programming Language Interview Questions and Answers Tutorial for beginners. Copyright 2013 All Rights Reserved