0
x = 42; int num = 0; while (num <3) Consele.writeline (x); num++; int x = 42; is just an int with an asigned value of 42 int num=0; is what initiate the count for the while loop while (num < 3); means 0<3 true, 1< 3 true, 2<3 true, the loop end at 2 bc 3 <3 is false consele.writeline (x) will display 42 while num < 3 num++ will execute and then add 1 to check if the while loop still true, but it stop at 2, bc 3 makes it false. so the consele.write will write 42 three times. x=42, remember the (x)
does this makes sense?
2 Respuestas
+ 1
the correct code is :
int x = 42;
int num = 0;
while ( num <5 ) {
Console.WriteLine( x );
num++;
}
0
output = 42
42
42