Why does this code print the following:
1 1 1
1 1 2
2 1 1
2 1 2
3 1 1
3 1 2
Code:
To my understanding i know why the middle is always 1, because once y == 2 it breaks. However why is it that x is not 2 in the second line? isn't x suppose to add 1 to its self after the first loop runs? Also z goes back to 1 on the third line.
Can anyone explain this to me, I'm slightly confused and have probably missed the reasoning for this somewhere.Too all the experts out this i know this is the stupidest question in the world, but I've literally just started and I'm looking to understand every bit that i can, rather than to pass it over.
1 1 1
1 1 2
2 1 1
2 1 2
3 1 1
3 1 2
Code:
Code:
#include <StdAfx.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x, y, z;
for (x = 1;x <= 3 ; x++)
{
for (y = 1; y < 3; y++)
{
if (y == 2)
break;
for (z = 1; z < 3; z++)
{
cout << x << " " << y << " " << z << endl;
}
}
}
int yes;
cin >> yes;
return 0;
}
To my understanding i know why the middle is always 1, because once y == 2 it breaks. However why is it that x is not 2 in the second line? isn't x suppose to add 1 to its self after the first loop runs? Also z goes back to 1 on the third line.
Can anyone explain this to me, I'm slightly confused and have probably missed the reasoning for this somewhere.Too all the experts out this i know this is the stupidest question in the world, but I've literally just started and I'm looking to understand every bit that i can, rather than to pass it over.