Computer Applications

Which of the following for loop will not be an infinite loop?

  1. for(; ;)
  2. for(a = 0; a < 1; a--)
  3. for(a = 0; ; a++)
  4. for(a = -1; a < 1; a++)

Java Iterative Stmts

12 Likes

Answer

for(a = -1; a < 1; a++)

Reason — In the selected for loop, the initial value of a (-1) will be incremented by 1 every time and eventually the condition (a < 1) will become false and the loop will terminate.

Answered By

5 Likes


Related Questions