Problem with labels

BlitzMax Forums/BlitzMax Beginners Area/Problem with labels

technician(Posted 2005) [#1]
All right, I'm forcing myself along here, but am having a problem with labels in my code. I've posted the code below. Basically my problem is that when I attempt to compile this I receive this error:

"Compile Error: Label 'start' not found"


' BASICalc
' Last edit on 6.17.2005


' Time to start input

#start
Print ""
Print "Simple calculator"
Print ""

whattodo$ = Input("Add, subtract, multiply or divide? (a,s,m,d) ")

If whattodo = "a"
Goto add
Else If whattodo = "s"
Goto subtract
Else If whattodo = "m"
Goto multiply
Else If whattodo = "d"
Goto divide
Else
Print "Error! Choose either a, s, m, or d!"
Goto start
End If

End


' Enter our labels for the different types of calculations

' Addition

#add
grabx# = Float(Input("x value > "))
graby# = Float(Input("y value > "))

Print "Result is: "+add(grabx,graby)

again()


' Subtraction

#subtract
grabx# = Float(Input("x value > "))
graby# = Float(Input("y value > "))

Print "Result is: "+subtract(grabx,graby)

again()


' Multiplication

#multiply
grabx# = Float(Input("x value > "))
graby# = Float(Input("y value > "))

Print "Result is: "+multiply(grabx,graby)

again()


' Dividing

#divide
grabx# = Float(Input("x value > "))
graby# = Float(Input("y value > "))

Print "Result is: "+divide(grabx,graby)

again()


' Exit

#done
Print "Bye!"
End


' ====================================================


' Let's declare some functions

Function add#(x#,y#)
Return x+y
End Function

Function subtract#(x#,y#)
Return x-y
End Function

Function multiply#(x#,y#)
Return x*y
End Function

Function divide#(x#,y#)
Return x/y
End Function

Function again()
Global again$=Input("Calculate another problem? (y,n) ")
If again = "y"
Goto start
Else
Goto done
End If
End Function



I'm wondering if BMax just doesn't like hopping back and forth through the code, or I'm not completely understanding labels and gotos. If someone could shine some light my way I would appreciate it!


Dreamora(Posted 2005) [#2]
Hopping around is no problem

But you can't hopp to a label that is not within the same scope -> jump into or out of function this way is not possible.

Sorry if this sounds rude, but this code is the worst example of spaghetti-code i've ever seen


technician(Posted 2005) [#3]
Sorry if this sounds rude, but this code is the worst example of spaghetti-code i've ever seen


I'm fairly new to programming (so it ain't going to be pretty), that's why I'm in the beginner forum. This example was to get myself into some functions, labels, and the like. It's a complete mess, but I learned a chunk from it.

I was wondering about going to and from a function with goto. I removed it and it works now, thanks.