ID:148838
 
I'm getting the following compile error from the code below: "error:auction_loop :continue failed". Does the switch statement mess up continue calls outside the switch? If not, I don't see what I'm doing wrong. Any help would be appreciated.


auction_loop:
for(var/obj/tile/T in auction_block)
switch(T.code)
if(2)
if((T.style == 2) && (rivers.len > 2))
for(var/obj/tile/TR in rivers)
if(TR.style == 2)
continue auction_loop
continue is used to keep looping onto the next object, you're trying to return back to a label, which you should use the 'goto' function for.
In response to Nadrew
Nadrew wrote:
continue is used to keep looping onto the next object, you're trying to return back to a label, which you should use the 'goto' function for.


hmmm... actually, I am trying to loop onto the next object, but I used the label so that I continue in the outer loop rather than the inner one (ie. in my example, keep looping on "auction_block" rather than on "rivers"). I'm pretty sure 'goto' won't work for me here, as that would start the outer loop over from the beginning, right?
In response to Dramstud
dramstud wrote:
Nadrew wrote:
continue is used to keep looping onto the next object, you're trying to return back to a label, which you should use the 'goto' function for.

hmmm... actually, I am trying to loop onto the next object, but I used the label so that I continue in the outer loop rather than the inner one (ie. in my example, keep looping on "auction_block" rather than on "rivers"). I'm pretty sure 'goto' won't work for me here, as that would start the outer loop over from the beginning, right?

If you only want to exit the inner loop, a simple break statement should do it. That will return you to the switch case you're in, which has nothing after the inner loop and promptly ends, and you'll continue the outer loop.

If you want to jump out of both loops, the label has to be after the outer loop. What Nadrew's saying is that the label can't be before the continue. To do what you're trying to do, a break would work as I mentioned, or you should put the label at the very end of, but within, the outer loop.

Lummox JR
In response to Lummox JR
I would need more than just the 'break' for reasons I won't get into (I wanted to keep my example simple by not including the code below the continue). While it wouldn't be too hard to work around this, I'd really like to understand why my current implementation doesn't work. Both of you are contradicting the example in the DM help (ie. highlight "continue" and hit F1):

client/verb/loners()
var/mob/M
var/mob/G

usr << "Loners:"
finding_loners:
for(M in world)
for(G in world)
if(M in G.group) continue finding_loners

//found a loner
usr << M.name


if this example (which I'm pretty sure matches what I'm trying to do) is wrong, we should let Dantom know about it.
In response to Lummox JR
This looks like a bug to me. The example given in the reference for continue with a label does not compile, giving the error message mentioned previously. A little investigation reveals that it was broken way back in version 272 (yes, I have all my old BYOND versions around). Works in 271, the earliest version I have.

As Lummox JR pointed out, an alternate method would be to put the label at the very end, but inside the auction block loop. Then change the continue to a goto, and it should have the same effect.

I suppose Dantom can either fix this or change the reference so that it's no longer supported. I can't think of an instance that isn't doable with the goto method. Surely nobody's using it since it hasn't worked for over a year and a half.