ID:406664
 
Keywords: break, continue, label, loop
What are everyones thoughts on using labels for loops and breaking/continuing using those labels? I know that goto is stayed away from (afaik because most people don't know how to use it properly). Is the same animosity attached to loop labels?

Here's an example of where I'm using it in some code...
// This is used to generate edges on turfs as a workaround for layering in SIDE_MAP format
DIR_LOOP:
for(d in L) // d is a direction, L is a list of directions
t = get_step(src, d)
// For turfs
if(isturf(src) && t && !istype(t, type))
new_edge(d)

// For other atoms
else if(t && !istype(t, type))
for(var/atom/a in t)
if(istype(a,type))
continue DIR_LOOP
else
new_edge(d)
Goto isn't as much of a problem in DM because you can't use it to jump to a different proc. In some languages, you can, which makes it possible to really complicate things. The loop label has to be placed in the same proc (even in other languages that support loop labels this is probably true) so that limits how complicated things can get. I don't think it's avoided as much as goto, but loop labels are so uncommon that it's hard to tell if they're avoided or just rare.

In the code you have there, replacing "continue DIR_LOOP" with "break" would have the same effect (assuming there's not more code following that). Even if there is more code, you can do something like this:

outer_loop:
for(var/a in something)
for(var/b in something_else)
if(istype(b, /something))
continue outer_loop

// do something else

// you can do this instead
for(var/a in something)

var/skip = 0
for(var/b in something_else)
if(istype(b, /something))
skip = 1
break

if(skip) continue

// do something else

Personally, I don't like loop labels because they look strange (you're never expecting to see them) and they require extra indentation.
Are there any advantages or disadvantages performance-wise using labels as opposed to variables like that, or is it mostly a preference for people based on readability?
The different in performance should be negligible. If your game's CPU usage is high, this wouldn't be the cause either way. The reason for doing this is readability more than anything else.

I forgot to mention this in the first post: needing loop labels can be a sign that you should split the code into two procs. Though that's probably not the case here.