-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.c
28 lines (24 loc) · 842 Bytes
/
loops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
int main(){
int i = 0;
for(i = 0; i < 10; i++){ // Initial value 0, until i is not less than 10, increment by 1
printf("%d", i);
printf(" ");
}
printf("\n");
int k = 0;
while(k < 10){ // Do while the condition is satisfied. If the condition is not, break. Check the condition then do the loop.
printf("%d", k);
printf(" ");
k++;
}
printf("\n");
int z = 10;
do { // First do the loop, then check the condition. In this case the loop is executed once, even though the condition is false.
printf("%d", z);
z++;
}
while(z > 100); // If this was a while loop, printf(z) would never have run.
// Can also have a break; statement to exit the loop or a continue; statement to go to the top of the loop.
return 0;
}