[wplug] about basic programming
Arnaud Loos
arnaud at arnaudloos.com
Fri Mar 4 16:02:50 EST 2005
The program would print out "Counting 39 up" then the num++ would increment
num to 40. Your while loop would then evaluate the statement (40 < 40) which
is false and therefore it would exit. If you had (num <= lastnum) then it
would print out "Counting 40 up".
Arnaud-
-----Original Message-----
From: wplug-bounces+arnaud=arnaudloos.com at wplug.org
[mailto:wplug-bounces+arnaud=arnaudloos.com at wplug.org] On Behalf Of Tom
Rhodes
Sent: Friday, March 04, 2005 3:52 PM
To: General user list
Subject: Re: [wplug] about basic programming
On Fri, 4 Mar 2005 14:03:13 -0500
John Harrold <jmh17 at pitt.edu> wrote:
> Sometime in March Juan Zuluaga assaulted the keyboard and produced:
>
[SNIP]: Discussion on books.
Perhaps someone with years of experiance in programming could tell me
something. In the following program snip-it:
#include <stdio.h>
#define lastnum 40
int main()
{
int num = 0;
while ((num == 0) || (num < lastnum))
{
printf("Counting %d up\n", num);
num++;
}
return 0;
}
num is only incremented to 39, one below 40. Thus far I have always
considered it was because we stop at the number before the one we define.
So I have always wrote as such. Yet, I have not found an explination in
either of my two C books.
Am I missing or not properly enterpreting a paragraph/sentence in my books?
Yea, I'm sure everyone thinks I'm nuts now since I should know this, but,
eh, whatever. *hand in the air* You don't know me!
:)
--
Tom Rhodes
_______________________________________________
wplug mailing list
wplug at wplug.org
http://www.wplug.org/mailman/listinfo/wplug
More information about the wplug
mailing list