MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the advantage of using a while loop versus a for loop?
A
You can repeat the code continuously
B
There is a pre-defined number of repetitions
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -Use a for loop when you know the loop should execute n times. Use a while loop for reading a file into a variable. Use a while loop when asking for user input. Use a while loop when the increment value is nonstandard.

Detailed explanation-2: -When would it be more beneficial to use a while loop instead of a for loop? When you need your loop to be controlled by user input. Adding a tracking variable to count the number of times a loop executes can be an effective way to measure efficiency.

There is 1 question to complete.