What is an infinite loop? Give an example.
Topic: Infinite loops
Answer
An infinite loop is a loop whose terminating condition never becomes false, so it goes on executing endlessly until the program is stopped by force.
Example: for(int i = 1; i > 0; i++) System.out.println(i); Here i only ever increases, so the condition i > 0 stays true forever.
Define it, then show one. Any correct example is accepted — while(true), a for loop with no update, or a condition that can never fail. The instructive kind is the one that looks correct: for(int i = 5; i != 0; i -= 2) steps 5, 3, 1, -1, -3 ... and skips straight past 0, so the test i != 0 never holds. That is why != is risky whenever the counter changes by more than 1 — worth adding as your example if you want to show real understanding.