Naming integers

Is there a method or reasoning behind what letters to choose when naming an int?


for (int i = 0; i < input.size(); i++) {

for (int j = 0; j < vowels.size(); j++) {

Why choose i & j here? Why not use a & b? Is there a reason, or is it completely aribitrary?

Tradition. Or, if you prefer, convention as you almost imply. Notice that “integer” begins with the letter i and that’s the type used for counting in loops. Of course, j follows.

1 Like

That makes sense!

I’m having a hard time following at times, and I think that part of it is because little instances like this aren’t explained all of time. It’s often recommended to google for help and examples. But when I do, things often look similar but different. I suppose that it’s a good thing to do the google searches so that we are then exposed to different ways of doing things and syntaxes. One of those differences is where you declare that you’re using the standard naming convention, so you don’t have to type std:: before you use something in the standard library. (Sorry if that isn’t exactly how it should be described. I’m still very new at all of this.) Also, things like NULL being purple in the example, but it types out red in the built-in IDE.

It’s little stuff like that that makes me second guess solutions at times, and I feel like that has a potential to throw many people off track. That being said, though, I appreciate the opportunity to dig a little deeper than CC and find even more information out. It’s a seriously deep rabbit hole. I’ve already spent hours of research outside of CC and saved MANY links to go back to.

Equally, as we may often find ourselves using a for loop to iterate over an object which supports indexing, the i could be for index… :slight_smile:


Today, I saw the reference to iterator in the C# lesson on for loops. Hmmm…it’s one of those things we could make up our own urban legend about. Kinda like, “How many licks does it take to get to the Tootsie Roll center of a Tootsie Pop? … The world may never know.” (Unless you ask Mr. Owl.)