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


How these loop execute ?



3/8/2021 2:33:17 AM

Shubham Maske

6 Answers

New Answer


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; }


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


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.


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


The condition for the entry of the loop is wrong


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