What will be the output of the following TypeScript code?let i = 0;do { i++;} while (i < 3);console.log(i);*1 point0123
Question
What will be the output of the following TypeScript code?
let i = 0;
do {
i++;
} while (i < 3);
console.log(i);
1 point
- 0
- 1
- 2
- 3
Solution
The output of the given TypeScript code will be 3.
Here's the step by step explanation:
- The variable
i
is initialized with the value 0. - The
do-while
loop starts executing. It first incrementsi
by 1, makingi
equal to 1. - It then checks the condition
i < 3
. Since 1 is less than 3, the loop executes again. i
is incremented again, makingi
equal to 2.- The condition
i < 3
is checked again. Since 2 is less than 3, the loop executes one more time. i
is incremented once more, makingi
equal to 3.- The condition
i < 3
is checked again. This time, since 3 is not less than 3, the loop stops executing. - The value of
i
(which is now 3) is logged to the console.
Similar Questions
What will be the output of the following code snippet?var a = 1; var b = 0; while (a <= 3) { a++; b += a * 2; print(b); }*4 10 181 2 3None of Above1 4 7
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 the following JavaScript code output?for (var i = 0; i < 3; i++) { setTimeout(function() { alert(i); }, 1000 + i);}
What is the output of following code?var a = 10;function test() { a = 20;}test();console.log(a);Options: Pick one correct answer from below1020
What will be the output for the following code?i=0while(i<3): j=0 while(j<3): print(i,j,end=" ") j+=1 print()
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.