this post was submitted on 29 Nov 2023
-7 points (40.0% liked)
Programming
17668 readers
174 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Well, sometimes it is possible to write a loop with
break
or without it, and in such cases solution withoutbreak
is better readable. But if you don't see a simple way to avoid usingbreak
, use it. It is very common, as well as having multiplereturn
statements in function. Evengoto
can be a good solution sometimes if it points to label located below and not very far.However you should avoid some antipatterns. If you write an infinite loop that is interrupted only by break, it is highly likely that you are doing something wrong. Nested loops with multiple breaks or gotos are very hard to read and debug. Such code usually can and should be rewritten for better readability and to avoid possible errors (occasional hangs, for instance).