Jump to content

  • Log In with Google      Sign In   
  • Create Account

What is wrong with this simple FOR loop?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Kevinator   Members   -  Reputation: 229

Like
Likes
Like

Posted 13 February 2002 - 10:54 AM

I''m having a rough time here. As you can see, I am an extreme newbie to C++ (although done some Basic and Pascal before), and the sybtax is a little different I''ve noticed. Even so, I don''t see what''s wrong with this code:
#pragma hdrstop
#include <condefs.h>
#include <conio.h>
#include <iostream.h>

//---------------------------------------------------------------------------
#pragma argsused

int main(int argc, char* argv[])
{

 for (int i=200;i>300;i++)
 {
  cout << "# " << i << "." << endl;
 }

 getch();
 return 0;
}
 
All I see when I compile and run this program is a blank screen, waiting for input from the keyboard (getch()). Any help would be greatly appreciated. Also, no errors or warnings are brought up by the compiler.

Sponsor:

#2 AdmiralBinary   Banned   -  Reputation: 100

Like
Likes
Like

Posted 13 February 2002 - 11:03 AM

LOL - replace the > with <.

---------------

I finally got it all together...
...and then forgot where I put it.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 13 February 2002 - 11:04 AM

I think this line is your problem

  
for (int i=200;i>300;i++)


it should say

  
for (int i=200;i<300;i++)





#4 eotvos   Members   -  Reputation: 127

Like
Likes
Like

Posted 13 February 2002 - 11:05 AM

your for loop should look like this:

for(int i=200; i < 300; i++)

then the rest of your code. Think of for statements as kind of a while loop that does the initialization, control, and iteration in one easy statement,even though when you get into the particulars of implementation the two..blah nevermind. Just think of the control statement in the for loop (the i < 300 part) as meaning the same as while(i < 300).

#5 Anozireth   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 February 2002 - 11:10 AM

all he needs to know is to remember that the > points to the smaller number.

#6 Kevinator   Members   -  Reputation: 229

Like
Likes
Like

Posted 13 February 2002 - 11:12 AM

Doh, I figured it would be something stupid. Thank you everyone, and eotvos your explanation helped clear it up. Thanks!

(Oh BTW: How do you do that cool thing where the code shows up all nice and pretty? I just used
 
.. )

#7 Kevinator   Members   -  Reputation: 229

Like
Likes
Like

Posted 13 February 2002 - 11:14 AM

Heh, it''s not that, it''s just that for some reason I was thinking with the logic "Repeat until i is greater than 300" instead of "While i is less than 300 do this".

#8 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 13 February 2002 - 11:20 AM

For the code stuff look here...

<a HREF="http://www.gamedev.net/community/forums/faq.asp">Forum FAQ</a>



#9 Kevinator   Members   -  Reputation: 229

Like
Likes
Like

Posted 13 February 2002 - 11:22 AM

Thanks.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS