Understanding Controlled & Count Controlled Loops

  • Thread starter Thread starter amaresh92
  • Start date Start date
  • Tags Tags
    Count Loops
Click For Summary
A controlled loop is defined as a loop that continues to execute based on a specific condition, such as user input, while a count-controlled loop is a type of controlled loop that runs a predetermined number of times. An example of a controlled loop is one that continues until a user responds with 'Y' or 'y', demonstrating that the number of iterations is not fixed. In contrast, a count-controlled loop, such as one that iterates five times, clearly defines the number of iterations before execution begins. The distinction between these types of loops is essential for understanding how to manage loop execution in programming.
amaresh92
Messages
163
Reaction score
0
greetings,
what is the meaning of controlled loop and count controlled loop?
advanced thanks.
 
Technology news on Phys.org
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
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 11 ·
Replies
11
Views
941
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
908
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
6K
  • · Replies 9 ·
Replies
9
Views
21K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K