What is an infinite loop? Give one example.
An infinite loop is a loop that never terminates because the condition never becomes false. In a looping construct, statements are executed repeatedly as long as a particular logical condition remains true. When the condition becomes false, the loop terminates. However, if the condition never becomes false, the loop continues indefinitely.
The statements within the body of the loop must ensure that the condition eventually becomes false; otherwise, the loop will become an infinite loop, leading to a logical error in the program. It is the programmer's responsibility to ensure there is an exit condition.
For example, if we did not set the condition count <= 100000 in a while loop, the program would have never stopped, resulting in an infinite loop.
Explanation
The textbook explains that looping constructs execute statements repeatedly based on a condition. The condition is checked using a loop's control variable, and when it becomes false, the loop terminates. The programmer must ensure this condition eventually becomes false to avoid an infinite loop. The context explicitly states that if the condition count <= 100000 was not set, the program would never stop - this is a clear example of an infinite loop situation. The textbook also mentions that infinite loops lead to logical errors in programs.