What will be the result?1. int i = 10;2. while(i++ <= 10){3. i++;4. }5. System.out.print(i);10111213
Question
What will be the result?
int i = 10;while(i++ <= 10){-
`i++;` }System.out.print(i);
10 11 12 13
Solution
The result will be 13. Here's the step by step explanation:
- An integer
iis initialized with a value of 10. - The
whileloop condition checks ifiincremented by 1 (i++) is less than or equal to 10. Sinceiis initially 10,i++in the condition will incrementito 11 but return the original value (10) for the comparison. So, the condition is true and the loop will execute. - Inside the loop,
iis incremented again by 1, makinginow 12. - The loop condition is checked again.
i++in the condition will incrementito 13 but return the original value (12) for the comparison. Since 12 is greater than 10, the condition is false and the loop will not execute again. - The value of
i(which is now 13) is printed.
Similar Questions
How does a WHILE loop start?{$a->questionintifier} Yanıta.while (i <= 10; i++)b.while (i <= 10)c.while i = 1 to 10d.while (i=0; i <= 10; i++)
What is the output of the following code snippet?int i = 0;do { if (i == 3) continue; System.out.print(i + " "); i++;} while (i < 5);
What will be the output of the following code? int i = 1;while(i<10){ if (i / 2 == 2) cout << i << “ ”;i++;}
What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}
What will the result of num1 variable after execution of the following statements? int j = 1, num1 = 4; while (++j <= 10) { num1++; } ans.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.