Natural Loop Varible

This is a discussion on Natural Loop Varible within the A Brief History of Cprogramming.com forums, part of the Community Boards category; When I write a loop, I always naturaly use the varible n.a . I know it seems wierd but quite ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Natural Loop Varible

    When I write a loop, I always naturaly use the varible n.a. I know it seems wierd but quite a while ago, I wrote
    Code:
    struct LOOP { int a, c, d, e, f, g; }; LOOP n;
    in my program for loops becuase I already had a being used as a string, and now it's stuck with me, and I have and use it in practicly ALL my programs. Whats your natural loop varible?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    19,550
    Not to be egotistical or anything, but it is i.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    i. if it's nested, j k l etc.

    If it's an iterator I use some name to indicate it's an iterator to a type of data structure

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    5,683
    index, callNum, session, etc depending on object type I'm iterating
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    i, j, k, l for loops. iter, iter2, iter3 for iterators.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,042
    x, y, z and then sometimes a, b etc or rarely i and j. (Usually I don't have that many loops though.)

    I must say that Queatrix's loop variables are probably unique.

    There was a thread much like this a while ago . . . maybe it got lost in the board restore.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    i normally. However, depending on the order of nesting it will start with k or j. Then it goes into ii, ij, ik, ji, jj, jk ... I think ye get the idea.

    I made that up. Sorry.

    i, j, k .... I use single letter variables for my iterator thingys, or a c for a colouring class, m for a menu class, and a d for a default class. To be honest if I have to use i, j, k, l (here I would run into problems), and one more I should probably have to rethink the code I'm writing.

  8. #8
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    i used to use count, count2, count3, etc..
    but that took too long to type
    i changed to i and j, i never nested more than 2 for loops since that change

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    i, j, k. Very rarely will I do other index variables for loops, at least not for for loops.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    I would use i, j, k if there was no context or for examples, but that rarely happens. I find myself using index a lot since most of my integer for loops involve indexes in an array-style container. I also use current_[object name] for iterators. Anything else I try to give explicit variable names as well, just like any other variable.

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,515
    i for single for loops.

    j,k,l for nested for loops.

    index, offset for non-for loops.

  12. #12
    Supermassive black hole ahluka's Avatar
    Join Date
    Jul 2005
    Location
    South Wales, UK
    Posts
    1,709
    Always i for single, j,k,l for nested (I've never gotten to m, thankfully).
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  13. #13
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,470
    There was a thread much like this a while ago . . . maybe it got lost in the board restore.
    That was my thread. It was a little while back. I asked if i j and k variable names were taken from the Fortran language. I think Prelude said I was correct, but all variables have been this way. Hmm, I remember using short variable names when I used to code in BASIC for the Acorn systems back in the early 90's. I miss this:

    Code:
    LET A = 200
    ahh, memories... :P
    I'm just trying to be a better person - My Name Is Earl

  14. #14
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,681
    Usually i, j, k... although many times I'll use loop, loop1, loop2, etc..
    I used to be an adventurer like you... then I took an arrow to the knee.

  15. #15
    Registered User
    Join Date
    Sep 2001
    Posts
    753
    Using i, j, k as index variables is older than programming. Those are the standard indexing variables for math proofs as well.
    Callou collei we'll code the way
    Of prime numbers and pings!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  3. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21