Computer Applications
Identify which of the following leads to an infinite loop.
- for(i = 10; i != 0; i--)
- for(i = 3; i <= 30; i += 3)
- for(i = 1; i >= 1; i++)
- for(i = 1; i >= 0; i--)
Java Iterative Stmts
2 Likes
Answer
for(i = 1; i >= 1; i++)
Reason — In the loop for(i = 1; i >= 1; i++), the condition i >= 1 will always be true because i starts at 1 and increases by 1 in each iteration. Since i is always greater than or equal to 1, the loop condition never becomes false. Therefore, the loop runs infinitely, causing an infinite loop.
Answered By
2 Likes
Related Questions
State which access specifier is less restrictive.

- private
- protected
- default
- public
The AMB hotel gives the amount to be paid by the customer as an integer, which of the following Math method rounds off the bill in decimals to an integer?
- Math.round()
- Math.pow()
- Math.ceil()
- Math.abs()
Assertion: A class can have multiple constructors.
Reason: Multiple constructors are defined with same set of arguments.
- Assertion is true, Reason is false.
- Both assertion and Reason are false.
- Both assertion and Reason are true.
- Assertion is false, Reason is true.
Assertion: An array can store elements of different data types.
Reason: An array is a user-defined data type with multiple values of the same data type but a different memory index.
- Assertion is true, Reason is false.
- Both assertion and Reason are false.
- Both assertion and Reason are true.
- Assertion is false, Reason is true.