The continue Statement in C

The continue Statement in C
The continue Statement in C
  • The keyword continue allows us to take up the control to the beginning of the loop, bypassing the statements inside the loop, which have not yet been executed.
  • When continue is encountered inside any loop, control automatically passes to the beginning of the loop.
  • A continue is usually associated with an if.

Let’s consider the following example:

main( )
{
int i, j ;
for ( i = 1 ; i <= 2 ; i++ )
{
for ( j = 1 ; j <= 2 ; j++ )
{
if ( i == j )
continue ;
printf ( “\n%d %d\n”, i, j ) ;
}
}
}

Output of the above program would be…

1 2

2 1

 

Note:

When the value of i equals that of j, the continue statement takes the control to the for loop (inner) bypassing rest of the statements pending execution in the for loop (inner).

 

Leave a Reply