Skip to content
thesarfo

Note

C: Statements

if, while, do-while, and for statements in C.

views 0
#include <stdio.h>
/* if statement*/
int main(void){
int i = 5;
if (i > 10) {
printf("Yes, i is greater than 10. \n");
printf("And this will confirm that\n");
}
/* while statement */
while (i < 10) {
printf("%d is less than 10\n", i);
i++;
}
/* do-while statement */
do {
printf("Do-while: i is %d\n", i);
i++;
} while (i < 10);
/* for statement */
for (i = 0; i < 10; i++) {
printf("i is %d\n", i);
}
printf("All done\n");
}