Linux Essay

822 Words Mar 28th, 2016 4 Pages
Short Answer Review Questions: Page 213

1.) Why should you indent the statements in the body of a loop?
You visually set them apart from the surrounding code. 2.) Describe the difference between pretest loops and posttest loops?
A pretest loop is a loop tests the condition before performing the iteration. A posttest loop performs the iteration, then tests the condition. 3.) What is a condition-controlled loop?
A condition-controlled loop uses a true/false condition to control the number of times it repeats.

4.) What is a count-controlled loop 5.) What three actions do count-controlled loops typically perform using the counter variable?
Initialization: Before the loop begins, the counter variable is initialized
…show more content…
Convert the While loop in the following code to a Do-while loop:
Declare Integer x=1
While x >0 Display “Enter a number.” Input c
End While
Do-While Code:
Main
//declare variables
Declare Integer x=1
Declare String doAgain
//The user can enter as many numbers as needed
Do
Display “Enter a number: “ Input x Display “Would you like to enter another number?” Display “(Enter y for yes):” Input doAgain
While doAgain == ”y”
End Module

8. Convert the Do-While loop in the following code to a while loop:

Declare String sure Do Display “Are you sure you want to quit?” Input sure While sure != “Y” AND sure != “y”
While Code:
Declare String sure
While sure == “Y” AND sure == “y” Display “Are you sure you want to quit?.” Input sure
End While

Related Documents