"goto cannot be used in strict mode"?

BlitzMax Forums/BlitzMax Programming/"goto cannot be used in strict mode"?

Sorry if this is a bit rough, it's been a long day..

You're asking for an unsupported language statement. It has nothing to do with style. It's the same as me suddenly writing in French and expecting you guys to understand it. That has nothing to do with style at all.

You're programming in a language, and programming, just like writing, is working within the limitations of that language whilst still being understandable. You might be able to pull off some weird crap in English and still be understood, but nobody is going to like you for it, and the fact you can doesn't mean that you should.

The style you use really has plenty to do with the language. Ask anyone that has used a more rigid language than C or Basic. Dropping the goto statement helps avoid any confusion over where and at what state a loop has terminated. Heavily nested loops are likely to use the stack, because the x86 doesn't have that many registers.

It's a throwback to assembly language of old, and doesn't fit as well with the way compilers are optimised to work now. Goto relates directly to a jump instruction, and a jump instruction, unlike a call, doesn't store and clear the stack. I'm not sure what exact implications would come of this, but if you didn't write your compiler to expect potentially extra stuff pulled or pushed on to the stack, once you try to pull off it, you could have a mess to deal with.

Of the two virtual machines and lexers/compilers I've written, neither of them included a goto like function, simply because of the potential headaches involved. But then I wasn't writing a full on basic compiler anyway.

The problem I have with Exit n is that it doesn't tell you what kind of loop you're exiting, and it's an ongoing maintenance issue, such that

For t = 1 to 20
   if job = nut then exit
   For u = 1 to 40
     if jeep = weep then Exit 1
     if goober = blog then exit 2
     For v = 8 to 400
        If blah = goo then Exit 3
        if meep = shoe then exit 2
     Next
   Next
Next

Add another loop, or fit in another for, and suddenly you have a mess on your hands. And my example has basically no code in it. Stick the usual mess that people put in for loops in there. That's why you'd want to be more explicit about what type of loop you're exiting at least (cos remember we have more than just for loops), and more so setting the variable to the max value will make that much clearer to you or whoever looks at your code later. It also fits quite well with While type loops.

You do raise a fair criticism of that method however, but it depends on the style you use :P The difference with Exit is it would kick you out straight away, whereas if you set the variable you'll still execute whatever is left in that loop before the Next.

You would have to customise your code to suit, and arguably this method is pretty ugly as well, as there could be a long list of variables to set, and again maintenance work to do should something change. Bear in mind though that you'd be dealing with the exact same situation if you elected to use a while/wend loop instead.

Exit is definately preferable to goto-ing out of a loop, which is ugly and hacky as hell in my point of view. If you must have a nested Exit, please somehow make it "Exit [loop type]" at least.

Oh, and the challenge is working within the constraints. You only have x many commands available to use to represent algorithm y. If this was meant to be easy you'd just magically have algorithm y already. Stupid example: If your language doesn't come with a command to input a whole string at once, only single characters, you write a function to stick the single characters together into a whole string. That's what programming is about, working within the language constraints, such as lack of a particular function, to get it to do what you want.

That's what essentially Warren has done, there's no Exit command for nested Fors so he's been using Goto. Unfortunately Goto has become deprecated, so unless it becomes available again, he needs to work around it.