The second form of loop construction obtainable in C is the whereas loop. Though at first look this construction appears to be easier than the for loop, it truly makes use of the identical components, however they’re distributed all through this system.
Let’s attempt to examine, as immediately as possil.e, the operation of the for loop and the whereas loop. The next program makes use of some time loop to breed the operation of our earlier forloop2.c program, which printed the numbers from 0 to 9 and gave a working complete.
/* wloop */
/* prints numbers from 0 to 9, retains working complete */
void principal(void)
int rely = 0; int complete = 0;
whereas (ccunt < 10 )
complete complete + rely;
printf(“rely=Xd, complete=%dn”, rely++, complete);
}
}
As earlier than, this program produces the next desk:
rely=0, complete=0
rely=1, complete=1
rely=2, complete=3
rely=3, complete=6
rely=4, complete=10
rely=5, complete=15
rely=6, complete=21
rely=7, complete 28