Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

King Newbie

a very simple newbie question

This topic is 5685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

in c++ is it possible to nest a leep inside and if then statment, or vise versa? If so, is there a certain place I would need to place it, or a certain method, or what?

Share this post


Link to post
Share on other sites
Advertisement
Absolutely,

If I understand you correctly...

if(!done)
{
for( x = 0, y = 0; y < SCREEN_HEIGHT && x < SCREEN_WIDTH ; x++, y++)
printf("stuff...");
}

and

for( i = 0 ; i != SCREENSIZE * SPRITELOCATION ; i++ )
{
if( sprite->location.x == HITWALL )
printf("Bounce");
}


or something. All the above code does nothing. It''s purely theoretical; but, the syntax is correct even if it''s not logical.

Share this post


Link to post
Share on other sites
in c++ is it possible to nest a leep inside and if then statment, or vise versa? If so, is there a certain place I would need to place it, or a certain method, or what?



?? i don't think I'm the only one that finds your post confusing.

I'll try to reword the question to what I think you're trying to say: In C++ is it possible to next a loop inside an if statement, or vise versa? If so, is there a certain place I would need to place it, or a certain method, or what?


First of all, from your original post I'll take it you program in visual basic, because if then is is VB, not in C++

C++ uses if (condition), VB uses If condition Then.

yes you can nest loops inside if statements and vice versa. Read some C++ tuts to find out where to place it.

Good luck


edit: Grammar

[edited by - ThomasSauder on October 31, 2002 2:46:23 PM]

Share this post


Link to post
Share on other sites
ack, I was trying to drink something while typing. Is it possible to nest a *loop* inside an if else statement, and vise versa. Sorry about that. And actiually I am learning c++, I said if then by habbit from back when I programmed using a mac game creation program called World Builder.

[edited by - king newbie on October 31, 2002 2:50:03 PM]

Share this post


Link to post
Share on other sites
No problem

The answer is yes.
I'll give you a simplified version, the other example given to you is, well over exaggerated for an example, and I personally think he's trying to show off

while (test!=result)
{
if (test>result)
{
std::cout << "too high" std::endl;
} else {
std::cout << "too low" std::endl;
}
}
std::cout << "Congradulations, it is equal to the number" std::endl;



that's the if else statement inside of a loop.
Now for the opposite

if (test!=result)
{
while (test>result && result>test)
{
std::cout << "Wrong number!" std::endl;
}
} else {
std::cout << "Right! They are equal!" std::endl;
}

edit: Stupid coding mistake

[edited by - ThomasSauder on October 31, 2002 3:00:13 PM]

Share this post


Link to post
Share on other sites
thanks, that really helps! Every time I tried nesting a loop with an if else statement I never could get it to work, but I have made this example work to my liking, thanks again!

Share this post


Link to post
Share on other sites
quote:
Original post by King Newbie
ack, I was trying to drink something while typing. Is it possible to nest a *loop* inside an if else statement, and vise versa. Sorry about that. And actiually I am learning c++, I said if then by habbit from back when I programmed using a mac game creation program called World Builder.




Are you looking to use the ''loop'' command? If so, there is no ''loop'' command in C/C++ although you can loop via do-while, while, for, and a few myriad, creative other ways.

- Advice, eh? Well, besides working on your swing...you know, besides that...I''d have to think.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!