was wondering is it really bad programming to use GOTO and Labels while i c it very usefull in speciefic situations..........
?????????????????????????????????????????????????? ???????
was wondering is it really bad programming to use GOTO and Labels while i c it very usefull in speciefic situations..........
?????????????????????????????????????????????????? ???????
Programming is a high logical enjoyable art for both programer and user !!
not necessarily, goto's should be used sparingly but are far to powerful a tool to be completely ignored!
they are as you say quite useful in situations, where any other method would be excessivly painful, and unecessarily long.
they are not the evil that is claimed if used properly where they are needed.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
I think their evilness is often over-emphasised so that new programmers don't get into bad habits. Having said that there aren't any situations where they are really necessary, but they can be useful in optimising something like tail recursion (if your compilers optimiser isn't up to the job) or a quick jump out of a nested loop.
>Having said that there aren't any situations where they are really necessary,
the how would you solve this little delima more eloquently, though simplified can come up quite often
Pseudocode:
Code:// stuff... for(val,value; val != whatever; val updated) { dostuff(); for(;value != whateverelse;value updated) { switch(value) { case 1: dosomething(); break; case 2: updatesomething(); // uh oh special exit condition reached!!!! we need to get back to the main loop goto MAIN_LOOP; break; case 3: dosomething(); break; } } MAIN_LOOP: dosomethingwithvalue(value); } // more stuff...
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
You could set a flag. I didn't say anything about what people find more eloquent and actually mentioned that they could be useful in jumping out of nested loops for speed; but the fact remains that they're not necessary. There's always another way to code something in C++ where they're not required.
>There's always another way to code something in C++ where they're not required.
this is not really a "technically" correct or incorrect statement the use of a goto is especially in a far more complicate version i could write up neccessary in this situation since virtually any other method would be a complete waste of resources, time, code length, complexity, and effort, and in my !Opinion! for lack of a more precise and better word "incorrect".
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
Code:// stuff... for(val,value; val != whatever; val updated) { dostuff(); for(;value != whateverelse;value updated) { switch(value) { case 1: dosomething(); break; case 2: updatesomething(); // uh oh special exit condition reached!!!! we need to get back to the main loop break; case 3: dosomething(); break; } if (value == 2) break; } MAIN_LOOP: dosomethingwithvalue(value); } // more stuff...
Last edited by swoopy; 07-01-2002 at 03:20 PM.
It is a technically correct statement. It doesn't matter how much more hassle it is because you have chosen to structure your code in a particular manner, it is still possible to do it without gotos (and it may possible to make it alot less work than you think with a bit of restructuring). It has nothing to do with opinion.
nice snoopy but, like i said this i much simplified version, and just an example for the purpose of discussion.
and this is as stated opinion of eloquence... and in my honest opinion thats ugly, especially if you had a dozen case's which required this exit fro mthe sub loop...
so stop being a smarty!! heheh.
>It doesn't matter how much more hassle it is because you have chosen to structure your code in a particular manner<
how else could i structure it?
It wouldn't be worth the trouble to complete restruture the code just to prevent the use of a goto! whats the point!!
>and it may possible to make it alot less work than you think with a bit of restructuring
this is in some cases true, but not all.
> It has nothing to do with opinion.
it has everything to do with opinion!!
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
>how else could i structure it?
It's hard to say with the contrived example you've given as I've no way of knowing what you're attempting to achieve. A quick hack alternative might look something like -
Code:for(val,value; val != whatever; val updated) { dostuff(); for(;value != whateverelse;value updated) { if(value==1){ dosomething(); continue; } if(value==2){ updatesomething(); if(special condition) break; else continue; } if(value==3){ dosomething(); continue; } } dosomethingwithvalue(value); }
>it has everything to do with opinion!!
What does? I wasn't refering to which one looked nicer or took less work, but to your assertion that it was not technically correct that it's possible to do it without gotos, which is false.
>What does?
THE USE OF GOTO'S!!
> technically correct that it's possible to do it without gotos, which is false.
reread the post i sent it before i finished what i was saying...
it was meant as "this is not really a "technically" correct or incorrect" but to say that it is always possible does not mean its always better... maybe technically was not the best term but, allow me to clarify my meaning.
it is not technically correct to do something total unneccessary and complex to avoid the use of gotos,
in my (as stated)OPINION!, it is not technically correct, please read it in the context it was stated in.
thank you guys for ur response.... after all I would like to tell you I agree totally with (Unregistered) its legal statement, however its real bad habit , and programmers should avoid it(even if this ll cost longer code)
one of the most experienced programmer(the author of Teach yourself C++ in 21 days) mentioned that he needed to use (GOTO ) once in 10 years of programming with C++ !
thanks you all again
Programming is a high logical enjoyable art for both programer and user !!
if the author of your book thinks it takes just 21 days to learn c++
then u should'nt listen even listen to the guy
hehehe........I agree with you defenitly, anyone who says that learning c++ needs 21 days , we shouldnt listen to him, but in fact the man didnt say that. He just offers a nice introduction to the c++ away from the dry books, in fact its very good book as a beginning. and at the last chapter he adviced the readers to go ahead for more comlicated books just likec " effrctive c++" and "c++ the programming language"
Programming is a high logical enjoyable art for both programer and user !!