+ 2
How many times the loop will run pls explain it?
Int x=-5; while(x<0){ x++; }
17 Réponses
+ 1
Thanks for ur explanation jayakrishna
+ 1
5 times that is x=-5,-4,-3,-2,-1 when it comes to 0 the condition (x<0 ) fails so the loop will run for 5 times
+ 1
Syntax error
Int is not capital
int is written in small letter always
0
saseentharan p
0 ( zero ) times, because the condition inside the while loop will evaluate to false because x = 5 which is more than 0
but the codition is asking for x < 0 then only it will run, if x = -1 then the while loop will run
0
But there was x=(minus)5 only so the condition was true only
0
when x = -5, -4, -3 , -2 , -1
0<0 is false so 5 times..
saseentharan p you can count like this,.. Take pen paper , wrote down.
You can observe it clearly yourself..
NonStop CODING you may not observed, it's negative 5, x = -5 ..
0
saseentharan p
wooo man, did you just edited the code🤔🤔.
if x = -5, then the loop will run 5 times only
0
Jayakrishna🇮🇳
i think he wrote x = 5 first then he edited the code later.
0
No, I'm not editing it, you not clearly saw
0
oohk let's end this discussion
0
Haa ok
0
It will run 4 times I think
0
Loop will not work bcz its a logical error
0
First you need to change Int to int. After loop will run 5 times and condition will check 6 times.
0
First change Int to int then loop will run 5 times
0
5times
0
Its 4 iterations.
-5 to -4 == 1 iteration
-4 to -3 == 2 iteration
-3 to -2 == 3 iteration
-2 to -1 == 4 iteration
Stop because -1 is less than 0