1(vii)
Select the infinite loop:
- (a)for(int i = 1; i <= 10; i++)
- (b)for(int i = 2; i != 0; i -= 3)
- (c)for(int i = 5; i <= 5; i++)
- (d)for(int i = 1; i >= 1; i--)
Show SolutionHide Solution↓
for(int i = 2; i != 0; i -= 3)
Reason — The loop for(int i = 2; i != 0; i -= 3) is an infinite loop because the value of i starts at 2 and decreases by 3 in every iteration. Since i will never become 0 (it will take values like 2, -1, -4, -7, etc.), the condition i != 0 will always be true. Therefore, the loop will continue to run forever.