C Syntax Conditional Statements for

 

- Info:

- This tutorial shows how to use "for" conditional statements.

 

- Example:

- Create C Console Application Test.c.

 

Test.c

#include <stdio.h>

int main() {

int i;

int j;

/* SIMPLE. Output is "1 2 3 4". */

for(i=1;i<=4;i++){

printf("%i\n",i);

}

/* COMPLEX. Output is "1 2 3". */

for(i=1, j=5 ; i<=4 && j>2 ; i++, j--){

printf("%i\n",i);

}

/* BREAK. Output is "1 2 3" since we break out of for loop before condition i<4 is reached. */

for(i=1;i<=4;i++) {

printf("%i\n",i);

if(i==3) { break; }

}

/* CONTINUE. Output is "1 2 4" since display of number 3 is skipped. */

for(i=1;i<=4;i++) {

if(i==3) { continue; };

printf("%i\n",i);

}

return 1;

}