You could always try for( i=0;i<20;i++) and observe the error messages
Maybe then try
int i;
for(i=0;i<20;i++)
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,875
Solved Threads: 953
Skill Endorsements: 27
Why the hell is there an i, does it means something, it's just an easy way to remember something or what?.
Relax and read some Wikipedia -> loop counter
FYI. If you don't like (too) short variable names, you are free to pick your poison. I think, C++ standard recommends that an identifier would be allowed to be 1024 characters long (the minimum).
mitrmkar
Posting Virtuoso
1,834 posts since Nov 2007
Reputation Points: 1,119
Solved Threads: 399
Skill Endorsements: 8
I believe that 'i' is used in accordance with the rules of Hungarian Notion; a coding style used to self identify the type variables (int type vars use 'i').
Check out Hungarian Notation.
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 119
Skill Endorsements: 5
I believe that 'i' is used in accordance with the rules of Hungarian Notion; a coding style used to self identify the type variables (int type vars use 'i').
Check out Hungarian Notation.
Nope. i has been used long before Hungarian Notation.
From Wikipedia:
"The original Hungarian notation, which would now be called Apps Hungarian, was invented by Charles Simonyi, a programmer who worked at Xerox PARC circa 1972-1981, and who later became Chief Architect at Microsoft. It may have been derived from the earlier principle of using the first letter of a variable name to set its type — for example, variables whose names started with letters I through N in FORTRAN were integers by default."
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
Actually, it predates computer programming entirely; it comes from conventions in mathematical notation, where i, j and k are traditionally used to indicate the indices of arrays and the iterative variables of summation (big-sigma) operations.
Schol-R-LEA
Veteran Poster
1,089 posts since Oct 2010
Reputation Points: 495
Solved Threads: 173
Skill Endorsements: 13
One of the first real fortran program every written was about the gamma function, and in typical mathematical notation it evaluated [tex]\sum_{i=1}^{6} \frac{\gamma_i}{1+\lambda_i \tau}[/tex] ina typical math function. Unfortunately I haven't seen the original code for it. But the use if i,j,... etc is extremely common for subscript in maths notation, so given that it was mathematicians that were the originators of computing, their notation become standard were it is applicable.
However, the first fortran compile manual [IBM 704] (published in 1956), uses i as a loop variable in the very first program (finding the largest number in a set).
StuXYZ
Practically a Master Poster
681 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
Skill Endorsements: 0
Hey. Look, it's just a convention.
All you're saying is that I am creating a variable named i which has a data type of int.
The fact that it is so widely used as an example as well as in actual production code just means that it is universally accepted.
As the other contributors say, you don't have to use i.
The fact is that you can not use int because that is a reseved word, so i is the next best thing.
i keeps it short but it's not very meaningful.
Well, i'm pretty much a newbie into programming, merely because i'm just 15, but i really like informatics ( specially programing ) but i'm not that wealthy so, i can't pay for private teaching, or anything like that.
But if you want to, you can, that's what i say. I've been learning c++ from a while now ( few months ) but everytime i see some math operation i see the "for (int i<...." For example:
int lower limit,upper limit;
int range=upper limit-lower limit;
int number;
for(int i=0;i<20;i++)
{
number=lower limit+(rand()%range);
cout<<number<<endl;
}
Why the hell is there an i, does it means something, it's just an easy way to remember something or what?.
Sorry for the dumb question, but i'm really an autodidact so it's kinf of hard to get someone to explain me this.
SORRY! AND GREETINGS!
mlesniak
Junior Poster in Training
50 posts since Jul 2006
Reputation Points: 32
Solved Threads: 7
Skill Endorsements: 0