Below is the code the teacher gave me. She gave me the answer and full credit

My problem is that I have no idea how the multiple for loops are processed.
Will someone please explain each step of the process to create the first and 2nd lines?
My incorrect understanding is that the for loop's 1st line will be one space and no X; each subsequent line, up to line 20, would have one space and one X.
- FIRST LINE:
1st for: x is 1 and add 1 to x ... go to 2nd for: y=19 and add 1 to y ... output a single space and go to 3rd: z = 0 and z must be > 0, so do not process the following code, which is to display an X.
One main thing that might help you to understand what is going on would be to replace the spaces with something you can actually see like maybe S's, for example instead of:
cout << " "; //print spaces
change it to some like
cout << "S"; //print spaces
When you have a for loop inside of another for it is called a nested for loop, in this little program you have two nested for loops inside one main loop.
for (int x=1; x <= 20; x++)
Starts the first main for loop, this for loop will be use to count the lines in this case there will be 20 lines.
It creates an integer variable named x and initializes that variable to 1 // int x=1;
It then checks the condition of x if x is less than or equal to 20 then the condition is true and it will run one loop of code in the { } brackets below it. // x <=20;
Once the for loop runs that code in its { } brackets only one time it comes back to the top of the for loop and increments x and that changes x from 1 to 2 and it will continue this looping until x is equal to 20 // x++
The code under the first for loop (The line for loop) is two nested for loops and a cout. During the first iteration of the line for loop the variable x is equal to 1. The first nested for loop begins (the spaces for loop).
for (int y = 20-x; y > 0; y--)
It creates an integer variable named y and initializes that y variable to 20-x, you know that x is equal to 1 from the line for loop above, so this means 20-x is the same as 20-1 or 19. // int y = 20-x;
It checks the condition of y if y is greater than 0 then the condition is true and it will run one loop of the code in the { } brackets below it.
Once it runs that code in the { } brackets only one time it comes back to the top of the spaces for loop and decrements y and that changes y from 19 to 18 and it will continue this looping as long as y is greater than 0. // y--
The first time through this spaces loop since y is initialized to 19 it will print 19 spaces, the next time this spaces loop is run y will be initialized at 18 because x will be 19 and 18 spaces will be printed, then the next time will 17 spaces and then 16 spaces and so on.
After the first nested loop (The spaces for loop) has completed printing 19 spaces then the next nested for loop is run (The X's for loop, the loop that prints the X's).
Once this last nested loop has completed a end line is printed then the program goes back to the top of the line for loop and increments the variable x from 1 to 2 and check the condition of x if x is less than or equal to 20 then the condition is true and it will run one loop of code in the { } brackets below it, in this second loop of the line for loop x will be 2 and the next time through x will be 3 until x is equal to 20.