Jump to content
  • Advertisement

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

Advertisement
Sometimes..
C has got about a dozen different control structures each useful in various situations, I suggest you try to get comfortable with all of them.

[Edited by - doynax on June 3, 2005 9:04:36 AM]

Share this post


Link to post
Share on other sites
What language? In general, I would advice against it, unless you have no choice (like in old fashioned Basic).

Share this post


Link to post
Share on other sites
Quote:
Original post by aleksi1578
Well I program in C++/C.. Please can you tell some other ways than goto? or any tutorials that has some of them/all of them?
The function call is the basic method in C.
Try to find some introductory C book or equivalent online tutorials. A trip to your local library might not be a bad idea.

Share this post


Link to post
Share on other sites
You should not use goto instruction, as it is deprecated and shows bad coding habbits. Instead, you need to learn how to use loops [do, do-while, while, for], function calls and exception handling [the latter is C++ only, and rather an advanced topic].

As Doynax said, try to find a good C / C++ book or online tutorial and code as much as you can ;)

Share this post


Link to post
Share on other sites
That I can think of, gotos are never necessary in C++. And if I remember correctly, they don't obey scoping rules either. For example:

void SomeFunc()
{
int i = 0;
while (true)
{
std::string s('!', 1024);
++i;
if (i == 1)
{
goto end_of_func;
}
}
end_of_func:
}


I'm pretty sure that the std::string object won't get properly destructed, since it never officially goes out of scope. This is bad.

What specifically are you trying to accomplish, because I'm confident that it can be rewritten or redesigned slightly to not use gotos.

Share this post


Link to post
Share on other sites
It's a bit better [luckily] :). As far as I know, with goto you cannot leave or enter a block, so:

void SomeFunc()
{
int i = 0;
goto inside_loop; //error, cannot enter block
while (true)
{
inside_loop:
std::string s('!', 1024);
++i;
if (i == 1)
{
goto end_of_func; //error, cannot leave block
}
}
end_of_func:
goto end_of_func; //ok, now it is valid -> infinite loop ^^
}


As I said, I'm not 100% sure about it since I never use goto ;), but as far as I recall the label must be in the same block that the goto statement, not inside a subblock or superior block of code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!