In this lesson, he uses a for loop with it’s iterator starting at 1 and going to the target number, inclusive. Or,
for (int i = 1; i <= MaxGuesses; i++)
This is fine, and I understand that for total beginners, it may be more intuitive, but try to structure your for loops with i = 0 and using i < TargetNumber instead.
Why?
Well, there’s no difference, except that starting from 0 is standard in all programming. Even if it’s not your own personal preference or “personal standard”, you will encounter it so extremely frequently in programming in all languages that it’s one of those things you just have to learn and get used to and adapt to, or you’ll keep getting confused by it.
Typically, I’d say ditch what everyone else is doing and do what logically makes sense. But in this case, if you try to stick to initializing your iterators at 1, you’ll be overrun by the people (and computers!) that count from 0 (zero).
When a baby is born, are they 1 year old? No! They are 0. They become “1 year old” after living for 1 entire year. So if you’re born in 1985, you are “1” in 1986, right?
Here’s an old dad joke – 5 + 5 is 10 right? Okay, now count with me on your 10 fingers…
With your left hand, count
1
2
3
4
5
Now on your right hand, count
10
9
8
7
6
Okay - what’s 5 + 6?
11.
5 plus 5 equals eleven!
No, silly, because you count from zero! So when you count on your right hand, you must start at TotalNumber - 1. Or 9. In for loops, this simply means we count to less than rather than less than or equal to. So,
i < targetnumber instead of i <= targetnumber, and we start i at zero instead of 1.
This is how you will find for loops in the wild.
for (i = 0; i < TargetNumber; i++) { }
Shed the training wheels when you’re ready, but shed them sooner, rather than later.