+ 2
Why is it considered a bad practice to use the goto function for looping?
4 Réponses
+ 3
I can only recall using a goto once. I had a series of two nested counted loops and I needed to be able to break out of the entire structure from the inside early based on certain conditions:
for{
for{
if(stuff){
GOTO ENDOFLOOPS;
}
}
}
ENDOFLOOPS:
I could just have easily declared a boolean break variable and used it as part of the conditional for each loop, but in this instance I decided a GOTO was just as practical and just as readable.
+ 2
If fact the goto command was considered a bad practice in oldies programming lanuages, where was allowed "to jump" from any place to any place of program with it..
But now,only for leaving multilevel loops upon condition, the goto is a good practice.
+ 2
I agree with above answers actually goto was used in old specially low level programming language instead of writing and planning complex process language have given us for while do loops but in few cases where it needs finer controls you can use it if the language allows like c++
it uses a label like label:
and keyword goto label
+ 1
Please I I was trying to execute >>>2**2 on Python and it's showing me error please I would like to know why I did wrong there