I would like to say thank you to all the contributing members of the forum. Daniweb has been the result of many late night google searches and has provided some valuable knowledge to myself and I'm sure countless others. I'll start by saying I'm no _real_ programmer. I've played around with scripts for 10+ years, occasionally delving into more intricate languages and efforts. I've managed to hack my way through some unusual circumstances over the years, and am once again trying to further my programming knowledge.
My real question in this thread is about the simple for loop. I'm currently reading a book that expresses the loop such as this:
// Program to visually display a for loop
#import <stdio.h>
int main (int argc, char *argv[])
{
int i;
for ( i = 1; i <= 200; i++ )
printf ("The loop is at %i\n", i);
return 0;
}
Yet I will also see the loop also expressed as this in other texts:
// Program to visually display a for loop, again
#import <stdio.h>
int main (int argc, char *argv[])
{
int i;
for ( i = 0; i < 200; i++ )
printf ("The loop is at %i\n", i);
return 0;
}
The only difference is that the Initializer and the Conditional are modified. In the first example, it starts at 1 and increments until it reaches 200. In the second, it starts at 0 and increments until it reaches 199, since 200 is not less than 200. Both examples will effectively run identical to each other. This seems to fall under the same category as Indent Style and Programming Style [wikipedia.org]
As more experienced programmers, what are your opinions on this issue. I myself can read both examples the same, but is one generally preferred over the other? I don't want to start developing a bad habit of preferring the wrong one over the other.