+ 1
How many times will this loop run?
for(int x=0; x=10; x++){}
14 Respuestas
+ 21
infinite
+ 19
Its like @Sakshi said.. there isnt a false condition
+ 19
The value becomes 10 and does not increment after :/
Try this code in playground and see the output.
for(int x=0;x=10;x++){
cout<<x<<endl;
}
+ 10
the answer is infinite only
first X=0 then X gets incremented and X becomes 10 but then also it will go on increasing because in the condition it is mentioned( X=10 )and not (X<10) or
( X >10 )or( X<=10)or (X>=10)
+ 7
no no
it will check X=0
then inside the loop
see the incrementation X++
X increments up to 10 then it goes on incrementing because in condition it is not mentioned that X should be less than 10 or greater than 10 and the condition will never be false
see the condition again it's mentioned X=3 and not X==3 , that means X has been just assigned the value 3 , this will always evaluate to true and hence the loop will run for ever
+ 7
thanks for the appreciation😊
+ 5
re: @Sakshi, S!d (for later visitors)
int x = 9;
if(x=10) cout << "true" << endl;
else cout << "false" << endl;
output:
true
Get bitten by this error enough times and you'll develop an uncanny instinct for conditionals vs assignment.
+ 3
thanks SakshiGupta you made my day. this was one new thing in c++ i learned from you.
i will follow you.
+ 2
@S!d how?? condition is not true
+ 1
@HashimNabreez how?? see the condition.
+ 1
@DavidA your answer clicks to my mind.
thanks.
but i couldn't remember that error was an option in challenge.
+ 1
@SakshiGupta loop will first initialize x=0 then will chek the condition which is x=10 which is not true. isn't the loop will be terminated at once??
+ 1
3
0
Error. Condition is not boolean.