Sunday, December 13, 2009

4.7 THE break STATEMENT

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 simply written as

break;

without any embedded expressions or statements.

Consider once again the switch statement originally presented in section 4.6

switch(choice=toupper(getchar())) {


case 'R':
printf("RED");
break;


case 'W':
printf("WHITE");
break;


case 'B':
printf("BLUE");
break;



default:
printf("error");
break;

}

Notice that each group of statement ends with a break statement,in order to transfer control out of the switch statement.

No comments:

Post a Comment