(this probably belongs under discussion)
So, since Roblox are adding continue statements to Luau, the ability to restart a loop. I think we should bring up a related topic
In most languages, there is a break statement and a continue statement
Break stops the current loop and continues the code
Continue restarts the current loop
I’ve heard multiple people say to not use these statements because it’s ‘lazy programming’
I’m wondering if there’s anything wrong with using them
2 Likes
I see nothing wrong with using these keywords, they’re there for use so why not use them?
As a added benefit they’re most probably more efficient to use than multiple if statements.
I don’t exactly use break too much anyways, most of the time return superceedes it as I’m looping searching for something and then returning it for the function.
FYI:
Not exactly, it just skips the current iteration and moves onto the next - which is so much more handier than if statement galore.
1 Like
Whoever claims its lazy programming doesn’t care about efficiency. There are many use cases in my game where I’ve needed continue and had to setup if statements and finish the loop. In terms of laziness, well it’s literally a standardized way of doing loops, a lot of languages support it.
When it comes to break, if they say not to use it, they clearly need to learn better programming.
Take this example
local p = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
for i=1,#p do
local v = p[i]
if v == 2 then
table.remove(p,i)
break
end
end
Say you’re removing 2, without break, this loop continues another 18 loops. Whoever claims not to use these statements is crazy, and you shouldn’t take their advice from now on.
11 Likes