# Thread: C++ Programming Quiz - Loops

1. ## C++ Programming Quiz - Loops

Hello.

I just started learning C++ today from your wonderful tutorials on the website, thank you very much for those by the way. I would like to get this sorted because I'm finding it fun to learn here and it's easier that way. I've had some bad experiences with a book previously and I don't want to go through that again until I learned at least the basics. I hope this is the right section of the forum to post my question.

Thing is, I ran into a tiny problem at the Loops Quiz, the very first question.

1. What is the final value of x when the following code is run?

A. 10
B. 9
C. 0
D. 1
Code:
```int x;
for (x=0; x<10; x++)
{}```
I answered 9, but the correct one is 10.

Did I misunderstand the question? The final value for which the loop will occur is clearly 9, I also added a cout << x to the code above just to be sure and it showed me the same thing. For x=10, the loop will not happen because the condition is checked at the beginning, so why is the final value 10?

I'm sorry I realize this is a very beginner question but I don't want to mess anything up now and find out that it adds up later on to a larger list of misunderstandings that I'll have to sort out then.

2. But the x++ happens at the end of the loop.

x always ends up being the first value which FAILS the test, not the last value to PASS the test.

3. So, the correct order is value -> check condition -> execute block -> increment -> repeat?

That's how I understand it, x=9 goes through the condition and becomes 10 at the end of the block. It also explains why my cout << x in the block would be useless, since it won't let 10 back in the loop, let alone print it.

4. print x inside the loop, and print x outside the loop.

Apart from some issues with break and continue, a for loop is basically a while loop.

Code:
```for ( a ; b ; c ) {
d;
}```
can be written as
Code:
```a;
while ( b ) {
{ d; }
c;
}```

5. Oh yeah. Should have seen that one. Guess I better learn these without distractions, thank you very much!