Advertisements
Advertisements
Question
Select the infinite loop:
Options
for(int i=1;i<=10;i++)for(int i=2; i!=0 ;i-=3)for(int i=5 ;i<=5;i++)for(int i =1;i>=1; i - -)
MCQ
Fill in the Blanks
Advertisements
Solution
for(int i=2; i!=0 ;i-=3)
Explanation:
- The loop starts with the initial value i = 2. In each iteration, the value of i is decreased by 3 (
i -= 3). The loop condition isi != 0. - As the value of i changes as 2, −1, −4, −7, …, it will never become 0. Therefore, the condition
i != 0always remains true, and the loop never terminates, making it an infinite loop.
shaalaa.com
Is there an error in this question or solution?
2024-2025 (March) Official Board
