RosettaCodeData/Task/Jump-anywhere/FreeBASIC/jump-anywhere.basic

51 lines
1.0 KiB
Plaintext

' FB 1.05.0 Win64
' compiled with -lang fb (the default) and -e switches
Sub MySub()
Goto localLabel
Dim a As Integer = 10 '' compiler warning that this variable definition is being skipped
localLabel:
Print "localLabel reached"
Print "a = "; a '' prints garbage as 'a' is uninitialized
End Sub
Sub MySub2()
On Error Goto handler
Open "zzz.zz" For Input As #1 '' this file doesn't exist!
On Error Goto 0 '' turns off error handling
End
handler:
Dim e As Integer = Err '' cache error number before printing message
Print "Error number"; e; " occurred - file not found"
End Sub
Sub MySub3()
Dim b As Integer = 2
On b Goto label1, label2 '' jumps to label2
label1:
Print "Label1 reached"
Return '' premature return from Sub
label2:
Print "Label2 reached"
End Sub
Sub MySub4()
Dim c As Integer = 3
If c = 3 Goto localLabel2 '' better to use If ... Then Goto ... in new code
Print "This won't be seen"
localLabel2:
Print "localLabel2 reached"
End Sub
MySub
MySub2
MySub3
MySub4
Print
Print "Pres any key to quit"
Print