In: Computer Science
Why is an exit condition so important for a while loop?
a. | An exit condition is not vital. A while loop works fine without one. | |
b. | So the programmer knows when it is okay to leave the room. | |
c. | If no exit condition is provided, while loops cannot continue beyond one iteration | |
d. | It allows the loop to end instead of running indefinitely. | |
e. | While loops are unstable, and must know how to exi |
d. |
It allows the loop to end instead of running indefinitely. |
The option d is correct because a loop must be finite that means loop must stop at finite iteration. It must not be infinite loop. If we won't provide exit condition the loop runs indefinitely. In order to control this exit condition is must. Because after a finite iterations when exit condition occurs then the loop will stop. So exit condition is so important to end the loop instead of running indefinitely.