bypasses the loop’s logic and makes the code difficult to understand and debug. Most repetitive algorithms can be written with any of the three loops discussed above. But each loop
works best in different situations.
1.
The while loop: As we have seen, a
while loop is a pretest loop.
This loop is ideal when you do not want the loop to iterate if the condition is false from the beginning. It is also ideal if
you want to use
a sentinel value to terminate the loop.
A sentinel value is a special value that cannot be mistaken as a member of the list and signals that there are no more values to be entered. When the user enters the sentinel value, the loop terminates. 2.
The do-while loop: As we have seen, a
do-while loop is a sort of posttest loop.
This loop is