Skip printing a number for the given range of number using for loop and continue keyword

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Skip printing a number for the given range of number using for loop and continue keyword

To show: How to use the for loop and continue keyword to skip printing a number for the given range of number

 

 

// Using the 'continue' statement in for loop

#include <stdio.h>

 

int main(void)

{

int x;

 

for(x = 1; x <= 10; x++)

{

//skip the remaining code in loop only if x == 5

if(x == 5)

continue;

printf("%d ", x);

}

printf("\nUsing continue to skip printing the value 5\n");

return 0;

}

 

Output example:

 

1 2 3 4 6 7 8 9 10

Using continue to skip printing the value 5

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index