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 repeats.
Hence, the correct answer is option “B”.
Explanation of Solution
Condition controlled loop:
This is a loop which exhibits true or false condition to control the number of times that the loop repeats. For example: “while” loop is a condition controlled loop.
- The “while” loop first checks its expression and then, the statements inside the loop gets 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 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
Explanation:
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 gets failed.
Explanation of incorrect options:
Boolean:
Boolean is not a loop instead it is a data type which is represented with two values either true or false. This value is based upon the flow of the action performed by the program.
Hence, the option “A” is wrong.
Decision:
A decision is not a loop and it decides the case to be executed based upon the situation.
Hence, the option “C” is wrong.
Count:
This is a loop which repeats specific number of times and it keeps track of the counter variable to keeps track about the number of times that the loop executes. For example: “for” loop is a counter controlled loop.
Hence, the option “D” is wrong.
1
2
3
4
5
Want to see more full solutions like this?
Chapter 5 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (7th Edition)
Software Engineering (10th Edition)
Computer Science: An Overview (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- (Mathematical functions) Write a program that calculates and displays values for y when y=xz/(xz) Your program should calculate y for values of x ranging between 1 and 5 and values of z ranging between 2 and 6. The x variable should control the outer loop and be incremented in steps of 1, and z should be incremented in steps of 1. Your program should also display the message Function Undefined when the x and z values are equal.arrow_forward(Misc. application) Four experiments are performed, and each experiment has six test results. The results for each experiment are given in the following list. Write a program using a nested loop to compute and display the average of the test results for each experiment. 1stexperimentresults:23.23116.92725.428.62ndexperimentresults:34.845.227.936.833.439.43rdexperimentresults:19.416.810.220.818.913.44thexperimentresults:36.93949.245.142.750.6arrow_forwardAn action is taken if the condition is true, otherwise the control goes to the next statement. * Do While Loop Elself Statement Select Case Block If Statementarrow_forward
- An action is taken if the condition is true, otherwise the control goes to the next statement. * O If Statement O Do While Loop O Select Case Block Elself Statementarrow_forwardAll of the following are looping control structures except Select one: while loop do-while loop for loop do loop none; all of these are looping control structuresarrow_forwardTrue or False: You should be incrementing the control variable of a for loop True or False: you can use the control variable of a while loop after the loop has finished executing True or False: you can nest repetition structures in repetition structures True or False: you can nest selection structure in selection structuresarrow_forward
- A statement is a a control flow statement that repeatedly executes a statement or a series of statements while the value of a specific condition is truthy or until the value of a specific condition becomes truthy. Select one: a.decision-making b.loop C.fork d.breakarrow_forwardBug Collector - MUST BE WRITTEN IN PSEUDOCODE A bug collector collects bugs every day for seven days. Design a program that keeps a running total of the number of bugs collected during the seven days. The loop should ask for the number of bugs collected for each day, and when the loop is finished, the program should display the total number of bugs collected.arrow_forward5, Number Guessing Game Write a program that generates a random number between 1 and 500 and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. Count the number of guesses that the user makes. When the user correctly guesses the random number, the program should display a user-friendly message and the number of guesses. (HINT: Design your code with an If/Else structure nested inside of a loop. You decide which loop structure is best to use. Do not use break statements or exit(0) statement inside the loop structure. Design your loop to logically end when the test condition becomes false.) Here's a short demo of how the game should function. CAUveriperh Desktop CSSTEST Debug Project 12.exe Guess what…arrow_forward
- Sum of Numbers Problem Design a program in Python with a loop that asks the user to enter a series of positive numbers. The user should enter a negative number to signal the end of the series. After all the positive numbers have been entered, the program should display their sum.arrow_forwardIn C programming: A while loop will always be executed at least once, even if expression is initially zero. True False The while and for loops are known as the "test-at-the-top" loops. * True Falsearrow_forwardThe for loop is this type of loop.1. pretest2. posttest3. prefix4. postfixarrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr