|
|
Flow Control and Exception Handling - Label Statements
Syntax
identifier:
- can be used with loops or statement blocks
- must precede the statement
- useful with break or continue which normally terminate or continue the innermost block
outer:
for( i=0; i<10; i++ ){
for( j=10; j>0; j--){
if( j == 5 ) {
break outer; // exit entire loop
}
}
}
Output: 0 5
outer:
for( i=0; i<10; i++ ){
for( j=10; j>0; j--) {
if( j== 5 ) {
continue outer; // next iteration of i
}
}
}
Output: 10 5
| Note |
- two or more statements can have the same name as long as one is not enclosed within the other
|
Example Code
|