 How these loop execute ? | Sololearn: Learn to code for FREE!

+1

# How these loop execute ?

for(x=0;x=10;x++);

+4

Shubham Maske If you print value of x then this loop will work till infinite because after incrementing value of x you again assign with 10 (x=10) so output will be 10101010101010101010................. Execution Timeout. Try this code in Code Playground. int x = 0; for (x = 0; x = 10; x++) { cout << x; }

+2

It's an infinite loop if you wrap the condition in parentheses.

+2

It won't execute at all as it stands because it won't compile. Did you mean... for(int x=0; x<10; x++); which will loop 10 times but do nothing, except waste cpu cycles, because of the semicolon at the end of it.

+1

Shubham Maske #include <iostream> int main() { for(int x=0;x < 10;x++) { std::cout << x << std::endl; } return 0; }

+1

The condition for the entry of the loop is wrong

+1

for(x=0;x=10;x++); Output; null This condition is stop , don't executed the loop. for(x=0;x=10;x++) { Printf(x); } Output 0123456789