Loop in c

  • Thread starter amaresh92
  • Start date
  • #1
163
0

Main Question or Discussion Point

greetings,
what is the meaning of controlled loop and count controlled loop?
advanced thanks.
 

Answers and Replies

  • #2
33,503
5,190
First off, here's an uncontrolled loop (also called an infinite loop).
Code:
while (1)
{
  // do something
}
Here's an example of a controlled loop.
Code:
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.
Code:
i = 0;
while (i < 5)
{
  printf("%d\n", i);
  i++;
}
This loop will run 5 times, and prints
0
1
2
3
4
 

Related Threads on Loop in c

  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
2K
Replies
14
Views
783
  • Last Post
Replies
4
Views
3K
Replies
2
Views
2K
Replies
25
Views
19K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
11
Views
4K
Top