What kind of variable is always used with a flag-controlled loop? In a sentinel
ID: 3697438 • Letter: W
Question
What kind of variable is always used with a flag-controlled loop? In a sentinel controlled while loop (which is a pre-test loop), does the loop control variable have to be initialized before the loop executes, meaning, above the loop? What's the difference between break and continue? What happens immediately after a continue statement is executed? Compare these two loops: while (!found) while(choice != 'q') Which one of these loops is sentinel-controlled and which is flag-controlled? Consider this loop: num = 0; sum = 0; cin >> num; while (num != -1) { cin >> num; sum = sum + num;Explanation / Answer
13) bool variable
14) Yes the variable has to be intialized. This determines if the loop should be entered or not in the first place.
15) In break the loop is discontinued and the program executes the next statement after the loop. With continue the loop is again started from the beginning.
16) The rest of the statements in the loop are not executed and the loop starts the next iteration.
17)The first loop is flag controlled and it executes as long as found is false. The second is sentinel controlled loop and it executes until the value of choice becomes 'q'
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.