MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is a counter used for in iteration?
A
To keep track of how many different steps have been completed
B
To keep track of how many times the solution has iterated
C
Keep track of how many steps to repeat
D
None of the above
Explanation: 

Detailed explanation-1: -A count-controlled loop is used when the number of iterations to occur is already known. Steps that are part of the loop are indented . Indentation is used to show which steps are to be iterated. In this example, the variable ‘count’ is used to keep track of how many times the algorithm has iterated.

Detailed explanation-2: -A count-controlled loop is so called because it uses a counter to keep track of how many times the algorithm has iterated.

Detailed explanation-3: -The Count-Controlled while loop In this while loop an action is repeated a given number of times. A counter variable is created and initialized to a starting value before the loop is started. The condition that is tested before each iteration of the loop is whether the counter has reached a predetermined value.

Detailed explanation-4: -The major difference between the While and For looping structures is that a For loop will run a predetermined number of times. An example of the use of a For loop follows. In the above example the For loop will execute ten times.

There is 1 question to complete.