Why is it considered a bad practice to use the goto function for looping? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is it considered a bad practice to use the goto function for looping?

19th Nov 2016, 1:27 PM
Wallace Steven
Wallace Steven - avatar
4 Answers
+ 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.
19th Nov 2016, 2:31 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 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.
19th Nov 2016, 3:51 PM
Petr Hatina
Petr Hatina - avatar
+ 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
19th Nov 2016, 6:53 PM
Sandeep Chatterjee
+ 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
19th Nov 2016, 6:58 PM
otokiniye
otokiniye - avatar