Integer i : "Using Loops" LXF158

Comments, suggestions and questions about Linux Format magazine and the coverdiscs

Moderators: ChrisThornett, LXF moderators

Integer i : "Using Loops" LXF158

Postby Nuke » Thu Apr 26, 2012 10:31 am

Graham Morrison wrote :- " the initial for statement requires a variable which for some reason is nearly always called i in examples"

He is writing a bit tongue in cheek, but of course it stands for "integer".

More specifically the practice comes from Fortran, which was my first programming language. In IBM mainframe Fortran at least, all variables starting with letters between i and n were integers (geddit?) by default, and the rest were floating point. So many coders adopted this convention as a lifetime habit, and i is my own first choice for any counter.
Unsolved mysteries of the Universe, No 13 :-
How many remakes of Anna Karenina does the World need?
User avatar
Nuke
LXF regular
 
Posts: 217
Joined: Wed Feb 09, 2011 12:11 pm
Location: Chepstow, UK

Postby nelz » Thu Apr 26, 2012 11:43 am

When I learned CS at uni, i stood for index.

That was Algol68, so a lot more modern than Fortran :P
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8499
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Integer i : ¨Using loops¨ LXF158

Postby DavidMcCrossan » Thu Apr 26, 2012 4:45 pm

Dear Nuke, you are almost certainly old to been around when there appeared a memorable cartoon in the famous American satirical mag featuring a whimsical representation of a hippy with beard, flares, sandals and guitar been wheeled out of the Courtroom as he declaimed the message ¨ a petty girl, a glass of wine and a charge of Statutory Rape...¨

Best

David
DavidMcCrossan
LXF regular
 
Posts: 339
Joined: Fri Aug 19, 2005 9:46 am

Re: Integer i : ¨Using loops¨ LXF158

Postby Nuke » Thu Apr 26, 2012 6:10 pm

DavidMcCrossan wrote:Dear Nuke, you are almost certainly old to been around when there appeared a memorable cartoon in the famous American satirical mag featuring a whimsical representation of a hippy with beard, flares, sandals and guitar been wheeled out of the Courtroom as he declaimed the message ¨ a petty girl, a glass of wine and a charge of Statutory Rape...¨

Maybe, but I was never quite a contemporary of Omah Khayyam,

http://www.kellscraft.com/rubaiyatedition1.html

Image
Unsolved mysteries of the Universe, No 13 :-
How many remakes of Anna Karenina does the World need?
User avatar
Nuke
LXF regular
 
Posts: 217
Joined: Wed Feb 09, 2011 12:11 pm
Location: Chepstow, UK

Postby towy71 » Thu Apr 26, 2012 7:38 pm

i stands for interface as in gui :P
still looking for that door into summer
User avatar
towy71
Moderator
 
Posts: 4263
Joined: Wed Apr 06, 2005 2:11 pm
Location: wild West Wales

Postby Xelous » Mon Apr 30, 2012 3:27 pm

It was never important what i stood for, I've heard it called:

    Index
    Iterator
    Increment
    Integer
    eye


Its no important that it means anything, but that it is simple in the code to see what is implied by the programmer... and especially to make sure not to use j as the next value somewhere in the code...

At 3am on a coding kicker full of caffeine with the room all stuffy and the dog under the desk farting merrily, trying to decipher:

for (int i = 0; i < imax; i++) {
int jmax = i + 100;
for (int j = i; j < (jmax); j++) {

Is just horrible :lol:
Xelous
 
Posts: 16
Joined: Thu Apr 19, 2012 2:46 pm

Re: Integer i : "Using Loops" LXF158

Postby carl_h » Fri Jun 01, 2012 2:19 pm

Nuke wrote:Graham Morrison wrote :- " the initial for statement requires a variable which for some reason is nearly always called i in examples"


When I learned to program on a ZX Spectrum, I always used n, because in Sinclair Basic, for loops ended with a 'Next' statement, and 'NEXT n' was just two presses on the N key.
carl_h
 
Posts: 10
Joined: Sat Jul 02, 2005 12:53 pm

Postby Bazza » Thu Jun 07, 2012 7:50 am

Hey carl_h...

I always use n for a different reason - (n)umber...

(But yeah, with the speccy I was lazy too... ;o)
73...

Bazza, G0LCU...

Team AMIGA...
User avatar
Bazza
LXF regular
 
Posts: 1476
Joined: Sat Mar 21, 2009 11:16 am
Location: Loughborough

Postby einonm » Thu Jun 07, 2012 12:57 pm

I never use i for variable names, have you ever tried doing a grep for 'i' to find out all the places it's used? You'll end up hitting every 'if' in the file for one thing.

As a consequence I always use 'ii' or 'jj' instead - much easier to search.
einonm
 
Posts: 29
Joined: Fri Apr 20, 2012 10:19 am
Location: Cardiff, UK


Return to Magazine and coverdiscs

Who is online

Users browsing this forum: No registered users and 0 guests