It is used in any looping statement. It is also used to continue the execution of the current looping statement and it skips the other statement written in the current block after the continue statement.
If continue will be written in while / do-while block then control will be transferred to the conditional statement.
Syntax for continue keyword :
continue ; or continue < label > ;
< label > : It indicates that which loop execution will be continued in the current nesting block.
ab: // Here ab is a label for " for " loop.
for ( int i = 0 ; i < = 10 ; i ++ ) { }
ab1 :
for ( int i = 0 ; i < = 10 ; i ++ ) {
ab2 :
for ( int j = 0 ; j < = 10 ; j ++ ) {
ab3 :
for ( int k = 0 ; k < = 10 ; k ++ ) {
continue ; // Continue the current block k and control transferred to k++.
continue ab3 ; // Continue the current block k and control transferred to k++.
continue ab2 ; // Continue the current block j and control transferred to j++.
continue ab1 ; // Continue the current block i and control transferred to i++.
}
Use of continue with label
Let suppose we have multiple array with some value and we want to find some value i.e 34 is available or not then we need to go for nested loop. If we found 34 in any one array and then we need to find other values is the same array, then we can continue with next array and hence we can use here continue with label.
If continue will be written in while / do-while block then control will be transferred to the conditional statement.
Syntax for continue keyword :
continue ; or continue < label > ;
< label > : It indicates that which loop execution will be continued in the current nesting block.
ab: // Here ab is a label for " for " loop.
for ( int i = 0 ; i < = 10 ; i ++ ) { }
ab1 :
for ( int i = 0 ; i < = 10 ; i ++ ) {
ab2 :
for ( int j = 0 ; j < = 10 ; j ++ ) {
ab3 :
for ( int k = 0 ; k < = 10 ; k ++ ) {
continue ; // Continue the current block k and control transferred to k++.
continue ab3 ; // Continue the current block k and control transferred to k++.
continue ab2 ; // Continue the current block j and control transferred to j++.
continue ab1 ; // Continue the current block i and control transferred to i++.
}
Use of continue with label
Let suppose we have multiple array with some value and we want to find some value i.e 34 is available or not then we need to go for nested loop. If we found 34 in any one array and then we need to find other values is the same array, then we can continue with next array and hence we can use here continue with label.
EmoticonEmoticon