forked from davetang/getting_started_with_c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.c
More file actions
48 lines (36 loc) · 859 Bytes
/
Copy pathloop.c
File metadata and controls
48 lines (36 loc) · 859 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
int main (){
int n;
/* create array of numbers */
int series[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
/*
loop from 0 to 9 and
print out series
*/
int i;
for (i = 0; i < 10; i++){
printf("%d\n", series[i]);
}
n = 0;
while (1){
n++;
/*
On a continue statement, the loop will stop its current iteration,
update itself and begin to execute again from the top; the condition
below will skip odd numbers
*/
if (n % 2 == 1){
continue;
}
printf("%d is an even number\n", n);
/* exit loop when n = 20 */
if (n == 20){
printf("Reached 20 loops\n");
break;
}
}
do {
printf( "I will run once even when a condition is not met\n" );
} while (0);
return 0;
}