Jump to content
  • Advertisement

Archived

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

johnnyBravo

Is there a way to make a function similar to while statement?

This topic is 5454 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

You know how the while statement you put the: { //code } and it loops between the two {}. Is there a way to manually do that or is that just built into the language? thanks,

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster

I''m not sure I completely understand your question, but you could just do something like this:

while (condition)
{
myFunction();
}

or, like this:

void myFunction()
{
while (condition)
{
// code for the function goes here
}
}

Share this post


Link to post
Share on other sites
Uh... what exactly are you talking about? Do you mean like:
    int i = 10;
label:
{
bla
bblah
}
if(i--) goto label
...
Forgive me Lord, for I have sinned.

Share this post


Link to post
Share on other sites
you know how the while statement works.

You say while then you have the {} and it loops whatever inbetween the {}

I want to make my own while type statement, where if i type {} under it , it loops whatever in there, i know people are going to say use the while, there is a reason that i cant be bothred explaining why i want to do this.

Share this post


Link to post
Share on other sites
Yes...*cough* goto *cough* would be the way to do it. While loops are much much much much much better.

Share this post


Link to post
Share on other sites
quote:
Original post by johnnyBravo
I want to make my own while type statement, where if i type {} under it , it loops whatever in there,
Not really possibly, if I currectly understand what you''re after
quote:
i know people are going to say use the while, there is a reason that i cant be bothred explaining why i want to do this.
If so, I cannot be bothered to explain in more detail.

Share this post


Link to post
Share on other sites
If for some strange reason, you want one while loop to do different things at different times, you could use function pointers... like this:



void DoSomething()
{
}

void DoSomethingElse()
{
}

void GoofyWhile(void (*func)())
{
while (whatever)
{
func();
}
}

int main()
{
GoofyWhile(DoSomething);
GoofyWhile(DoSomethingElse);
return 0;
}


At least I think that''s how the syntax would look... check out funtion-pointer.org for more info

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!