-7
Real quick question about the "break"
(sh.itjust.works)
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
Follow the wormhole through a path of communities !webdev@programming.dev
The only time I've used break outside of switch statements is to break out of for each loops early, when I'm checking to see if at least one element in a collection meets a condition. I really don't think there's ever a good time to use continue, to be honest. And if you use a labeled break statement, that's a problem.
continue
is useful as a loop analog to early return in a function context, which helps keep indentation/nested conditionals under control and in turn improves code readability.