July 2015
Intermediate to advanced
380 pages
10h 15m
English
The first looping construct I’ll show you is the while-loop, and it’s the simplest, useful loop you could possibly use in C. Here’s this exercise’s code for discussion:
ex9.c
1 #include <stdio.h> 2 3 int main(int argc, char *argv[]) 4 { 5 int i = 0; 6 while (i < 25) { 7 printf("%d", i); 8 i++; 9 } 10 11 return 0; 12 }
From this code, and from your memorization of the basic syntax, you can see that a while-loop is simply this:
while(TEST) { CODE; }
It simply runs the CODE as long as TEST is true (1). So to replicate how the for-loop works, we need to do our own initializing and incrementing of i. Remember ...
Read now
Unlock full access