Concept explainers
Describe the process you would use to replace a do ... while loop with an equivalent while loop. What problem occurs when you try to replace a while loop with an equivalent do ... while loop? Suppose you’ve been told that you must remove a while loop and replace it with a do ... while. What additional control statement would you need to use and how would you use it to ensure that the resulting
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
C Programming Language
Web Development and Design Foundations with HTML5 (8th Edition)
Problem Solving with C++ (10th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- (For review) a. What’s the difference between a pretest and posttest loop? b. If the condition being tested in a pretest loop is false, how many times are statements in the loop executed? c. If the condition being tested in a posttest loop is false, how many times are statements in the loop executed?arrow_forwardStudy the following program and then answer the questions below A: What is the output of this program? B: What would happen if we remove the initialization of "counter" prior to the do-while loop? C: What would happen if the first variable is greater than the last?arrow_forwardConsider the following common task done repeatedly:• Read the next input (x = read())• If the input is not valid (valid(x)), exit the loop• Print the input read (print(x))• Repeat the loopUsing C++ syntax:Write the loop above using a pretest loop, posttest loop and a user-located loop control mechanism. From the three which one is more readable and why?arrow_forward
- Given the following program segment:for (i) Write a while loop that has the same output. (ii) Write a do...while loop that has the same output.arrow_forwardAnswer the following sentences true or false 1. The main difference between a do-while loop and the while loop is in the do-while loop the condition is tested at the end of the loop body. 2. In while loop, if the condition is not true, then the body of a loop will not be executed, not even once. 3. If you want to print from 10, then assign the value 0 during initialization.arrow_forwardFrom a software engineering point of view, what is the "best" kind of loop?arrow_forward
- use the c# programming language While and For loops (Solve using all three loops), you may code all three loops in the same project. //do-while loop int counter = 0, stop = 5; //initializer do { Console.WriteLine(counter); //code statement counter++; //updater }while(counter < stop); //checker //while loop int counter = 0, stop = 5; //initializer while(counter < stop) //checker { Console.WriteLine(counter); //code statement counter++; //updater } //for loop // initializer checker updater for(int counter = 0, stop = 5;counter < stop; counter++) { Console.WriteLine(counter); //code statement } Write a program to print the numbers 2 to 10 in increments of two on the same line. The output of your program should be 2 4 6 8 10 Write a Program to compute the sum of eight numbers. You will prompt the user…arrow_forwardWhen is it advantageous to use a DO loop rather than other kinds of loops? What are some examples of when an infinite loop is appropriate?arrow_forwardThere are several different types of loops, such as while, for, do-while, etc. For the initial post, imagine you will be creating a loop to run a specific number of times. Choose one of the loop methods to utilize and justify why you have chosen that method. Be sure to be in depth and justify your posts. For these discussions, there is not one specific answer, however in order to receive full credit you must not only provide what is requested, but also justify your statements.arrow_forward
- Actual timings. Instrument FrequencyCounter to use Stopwatch and StdDrawto make a plot where the x-axis is the number of calls on get() or put() and the y-axisis the total running time, with a point plotted of the cumulative time after each call.Run your program for Tale of Two Cities using SequentialSearchST and again usingBinarySearchST and discuss the results. Note : Sharp jumps in the curve may be explained by caching, which is beyond the scope of this question.arrow_forwardAnswer the following question.. a)In Labview, what are the conditional statements? c) What does Labview mean by tunneling? What are the many ways that delays may be used inside of a loop?arrow_forwardGive an example of a while loop, then provide the equivalent do-while loop and for loop. Then give a different example of a do-while loop, along with the equivalent while loop and for loop. Finally, give an example of a for loop, along with the equivalent while loop and do-while loop. Use your examples to illustrate the advantages and disadvantages of each looping structure, and describe those advantages and disadvantages.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning