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 (4th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Management Information Systems: Managing The Digital Firm (16th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Modern Database Management
Web Development and Design Foundations with HTML5 (8th Edition)
Electric Circuits. (11th Edition)
- EX:[AE00]=fa50h number of ones =1111 1010 0101 0000 Physical address=4AE00h=4000h*10h+AE00h Mov ax,4000 Mov ds,ax; DS=4000h mov ds,4000 X Mov ax,[AE00] ; ax=[ae00]=FA50h Mov cx,10; 16 bit in decimal Mov bl,0 *: Ror ax,1 Jnc ** Inc bl **:Dec cx Jnz * ;LSB⇒CF Cf=1 ; it jump when CF=0, will not jump when CF=1 HW1: rewrite the above example use another wayarrow_forwardEX2: Write a piece of assembly code that can count the number of ones in word stored at 4AE00harrow_forwardWrite a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so”, “Yes, of course!”, “I’m not sure”, and so forth. The program should read the responses from the file into a list. It should prompt the user to ask a question, then display one of the responses, randomly selected from the list. The program should repeat until the user is ready to quit. Contents of 8_ball_responses.txt: Yes, of course! Without a doubt, yes. You can count on it. For sure! Ask me later. I'm not sure. I can't tell you right now. I'll tell you after my nap. No way! I don't think so. Without a doubt, no. The answer is clearly NO. (You can access the Computer Science Portal at www.pearsonhighered.com/gaddis.)arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning