Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: i++? i--? why the "i"?

  1. #1

    i++? i--? why the "i"?

    hmm... this isnt' really a question about any particular problems i'm having, just kind of a more "why?" question...

    i always see examples of code for instance:

    if (i>5)

    just wondering why "i" is always used... could you use "a"? or "q"? or "fuzzy"? or any other variable? or is it proper syntax to use "i" and won't work without it? or just simply good coding practice... or just a "generic "insert your variable here"... or just one of those mysteries nobody will ever know...

    hopefully one of you gurus out there can help a relative beginner like me move one step closer to the understanding of actionscript and coding in general!

    much appreciated,

  2. #2
    'i' is usually used just because it is a convention in programming. you could rightly use any letter you want.. although i would not recomment you use words. single letters are pretty much the way to go.


  3. #3
    i think i stands for iteration, but i am not tottaly sure. you can use anything that is not a reserved word.

  4. #4
    In the classic text 'The C Programming Language' by Kernighan and Ritchie, i is commonly used as a loop variable. I got into the habit of using i when I was first learning C from this book (back in the 80s), and I imagine a lot of other old coders did too. Old habits die hard. K&R is the same book that popularized the classic 'hello world' program and a number of other coding memes, still in use today in C-like languages.

    Prior to learning C, I did a lot of BASIC programming, and I used to use x a lot of my loops. x being the classic variable name from my high school algebra class. I still sometimes use x & y, particular if I am looping on coordinates in 2-d space, but for a single loop I will tend to use i, leaving x & y free for other uses.

    I've occasionally written 3-way nested loops using i, j and k. My GAWD I'm a nerd.
    Last edited by jbum; May 28th, 2004 at 03:56 PM.

  5. #5
    awesome, thanks for the quick replies! exactly what i was looking for. man this forum rocks

  6. #6
    i always used x for all for loops

  7. #7
    i stands for index.

  8. #8
    Jbum, your flash experiments are amazing. Where did you learn to do all of that stuff? Was it just trial and error? Are you just a genious?

    --You should enter an actionScript battle sometime hehe

  9. #9
    Quote Originally Posted by Yeldarb
    Jbum, your flash experiments are amazing. Where did you learn to do all of that stuff? Was it just trial and error? Are you just a genious?

    --You should enter an actionScript battle sometime hehe
    holy crap lol.. im amazed

  10. #10

  11. #11
    Inquisitorial Boot
    I think "i" was around when one could only have a certain amount of variables in a program, way back in like cobol of fortran, or something. "i" "j" "k" I think up to "p" were used for in loop guards and counters, other letters were used for different types of variables. Yeah, as you nest more loops you tend to to up the alphabet from "i".

  12. #12
    It stems from Fortran. In Fortran, you can declare your variables if you want to, but if you don't they get a default declaration based on the first letter of the variable name.

    Variables that start with I through N are integers and all others are reals. So if you needed a loop variable, you started with 'i'. For the next one you took 'j' and so on.

    And then it just stuck...
    Last edited by Hans Kilian; May 29th, 2004 at 04:28 AM.

  13. #13
    pom's Avatar
    Senior Member
    Very interesting You know, I think that the use of i comes from mathematics. i is used in demonstrations (?? when you're trying to prove a theorem) in substitution to any integer. Just as n is traditionally the last one of those integers.

    In algebra, for instance, if you take a one-dimensionnal matrix, it's going to be written [a1, a2, ..., ai, ..., an].

    My 2 cents
    Last smoke by Ilyas : yesterday at 11:45 PM.

  14. #14
    You're probably right, Ilyas, that the developers of Fortran took the default declaration stuff from mathematics. In the early days computers were mostly used for number crunching and many of the people working with computers had a background in mathematics.

    Funny how something like that evolves and sticks around to this day.

    Reminds me of the story about how some parts of the space shuttle were the same size as two horse are wide:

  15. #15
    i does stand for iteration. check out the reference. its what the macromedia ppls thought would be good for looping, but i guess according to someother dude who posted it was used for C first.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012