Condition-Controlled Loop Description

Read Summary
Summary

The two types of loops in programming are condition-controlled and count-controlled loops. Count-controlled loops typically use a counter variable to perform three actions: initialization, test, and increment. A while loop can be designed to take a user input number, multiply it by 10, and store it in a variable called product as long as the product is less than or equal to 100. A do-while loop can be designed to ask the user to enter two numbers, add them, and display the sum. The loop will ask the user if they wish to perform the operation again. A while loop can be used to replace a while loop. Additionally, a do-until loop can replace a do-while loop. Programming exercises include a bug collector program that tracks the number of bugs collected in a week and a budget analysis program that calculates if the user is over or under budget.

Table of Content

What is condition-controlled loop? Condition- enthroned loop uses a true/ false condition to control the number of times that it repeats. What is a count-controlled loop? Count-controlled loop repeats specific number of times. What are three actions do count-controlled loop typically performed using the counter variable? Initialization, Test, Increment Algorithm Workbench Design a While loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in a variable named product.

The loop should iterate as long as product contains a value less than 100. //Declare product = O Do Display “Enter a number. ” Input number Product = number x 10 While product < = 100 Design a Do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate.

This essay could be plagiarized. Get your custom essay
“Dirty Pretty Things” Acts of Desperation: The State of Being Desperate
128 writers

ready to help you now

Get original paper

Without paying upfront

Declare Minimum as Reliance ENUM as Reallocate sum as realistically “What is your first number”lineup 1 individuals ‘What is your second enfeeblement’s unassuming Minimum+individuals “sum mum” Convert the While loop in the following code to Do-While loops: Declare Integer x While x > O Display “Enter a number. Input x End While Declare x as Integer = 1 DO If x ! = O then Display ‘Try again” End if until x -o Display number you entered is correct” Convert the Do-While loops in the following code to a While loop: Declare String sure Display “Are you sure you want to quit? Input sure While sure ! = “Y” And sure Convert the following Do While loop to a Do Until loop: structuring = String. Empty Do While structuring. Toupee ” Y” Structuring = Inputted(” Are you sure you want to quit? ) Loop Programming Exercises Bug Collector A bug collector collects bugs every day for seven days. Design a program that peps 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.

Declare counter as integer =1 Declare bugs as integer = O Declare totals as integer = 0 For counter Display ” Enter of bugs collected today. ” Input bugs Set totals = totals + bugs End for Display ‘The total number of bugs collected this week was: totals Budget Analysis Design a program that asks the user to enter the amount that he or she has budgeted for a month. A loop should then prompt the user to enter each of his or her expenses for each month, and keep a running total.

When the loop finishes, the program should display the amount that the user is over or under budget. Declare Talladega as integer = O Declare totalities as integer = 0 Declare budget as integer = O Declare bill as integer = 0 Display “Enter your monthly Budget ” Input budget Display “Enter the amount bayou bill” Input bill totalistic = bill + bill Set Talladega = budget – bill If Talladega < = 0 then Display ” You are over your budget. Your budget is “, budget, ” and you are at “, delegate Until bill = O Display mayo are under budget.

Cite this page

Condition-Controlled Loop Description. (2018, Jul 03). Retrieved from

https://graduateway.com/condition-controlled-loop-description/

Remember! This essay was written by a student

You can get a custom paper by one of our expert writers

Order custom paper Without paying upfront