+ 1

For loop outputs

I am pondering about the output for the following two sets of code: 1) #include <iostream> using namespace std; int main() { for (int a = 10; a >= 0; a -= 3) { cout << a << endl; } return 0; } 2) #include <iostream> using namespace std; int main() { int x; for(x=0; x<4; ++x) { } cout<< x << endl; } The former one, as expected, prints out: 10 7 4 1 The latter one, however, only prints out: 4 Why won't the latter code print the following? 0 1 2 3

23rd Jul 2020, 10:23 AM
Solus
Solus - avatar
4 Respostas
+ 3
Add cout << x << endl; inside the for-loop body, it is currently empty.
23rd Jul 2020, 10:25 AM
Ipang
+ 2
Relax bro BTDT 😁
23rd Jul 2020, 10:35 AM
Ipang
+ 1
*facepalms*
23rd Jul 2020, 10:29 AM
Solus
Solus - avatar