View Full Version : loop in c
amaresh92
Jan20-11, 07:06 AM
greetings,
what is the meaning of controlled loop and count controlled loop?
advanced thanks.
First off, here's an uncontrolled loop (also called an infinite loop).
while (1)
{
// do something
}
Here's an example of a controlled loop.
while (response != 'Y' && response != 'y')
{
printf("Do you want to continue?");
response = getch();
}
The loop above is controlled, but there is no way of knowing how many times it will run.
Finally, here is a count-controlled loop.
i = 0;
while (i < 5)
{
printf("%d\n", i);
i++;
}
This loop will run 5 times, and prints
0
1
2
3
4
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.