Concept explainers
A_________-controlled loop uses a true/false condition to control the number of times that it repeats.
a. Boolean
b. condition
c. decision
d. count
The “while” loop is a condition-controlled loop; it controls the number of times that the loop repeats.
Hence, the correct answer is option “B”.
Explanation of Solution
Condition controlled loop:
This is a loop that exhibits true or false condition to control the number of times that the loop repeats. For example, the “while” loop is a condition-controlled loop.
- The “while” loop first checks its expression, and then the statements inside the loop get executed. It is also called as pretest loops.
- The loop gets terminated when the condition becomes false.
Syntax:
Syntax for the “while” loop is as follows:
while boolean_expression:
# while suite
Example Program:
Consider the following example of the condition-controlled loop:
#initialization of variable
a=1
#execute the while loop until a is less than or equal to 5
while a<=5:
#Print the value of a
print(a)
#Increment a by 1 for each iteration of loop
a+=1
zOutput:
1
2
3
4
5
In the above code, the “while” loop executes until the value of “a” is less than or equal to 5, and then it exits from the program when the condition inside the loop fails.
Explanation for incorrect options:
Boolean:
Boolean is not a loop instead it is a data type that is represented with two values either true or false. This value is based upon the flow of the action performed by the program.
Hence, option “A” is wrong.
Decision:
A decision is not a loop, and it decides the case to be executed based upon the situation.
Hence, option “C” is wrong.
Count controlled loop:
This is a loop that repeats a specific number of times, and it keeps track of the counter variable to track about the number of times that the loop executes. For example, “for” loop is a counter-controlled loop.
Hence, option “D” is wrong.
Want to see more full solutions like this?
Chapter 4 Solutions
Starting Out with Python (4th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Concepts of Programming Languages (11th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Digital Fundamentals (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)