Android Question GoTo line

Almog

Active Member
Licensed User
Hello,

Is there a way in code to skip to specific line by goto?

For example:

B4X:
If Succes Then
    Msgbox("","")
Else
    goto gg
End If

File.WriteString(File.DirInternal,"1.txt","")

gg: Msgbox("End","")

(what will happen is that if Succes = false then it will directly go to line gg and Msgbox without creating the file "1.txt".)

Thanks in advance.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
There are no goto statements, use the true/false conditions to control what you do.

B4X:
' // true 
If Succes Then
    Msgbox("","")
    File.WriteString(File.DirInternal,"1.txt","")
' // false condition
Else
  '  do something
End If
 
Upvote 0

Yayou49

Active Member
Licensed User
Or you can use a new sub:

B4X:
' // true
If Succes Then
   aa
' // false condition
Else
  bb
End If

Sub aa
 Msgbox("","")
    File.WriteString(File.DirInternal,"1.txt","")
end sub

Sub bb
 ' do something else
End sub
 
Upvote 0

mixdes

New Member
sorry to jump into the issue even though i am just starting my learn in B4A, however, i have been working with Basic Language since around 40 years, and Goto Statement is very essential to control the flow of your application, and your reply regarding the use of IF statements is not a full solution. it can solve the issue if you have limited number of statements in your code, but if you have large related code that is dependent on specific conditions and you have to divert the flow of code to some other location based on that specific conditions then it will be very hard to repeat the IF statements where ever you need to take action based on that value. so i highly recommend to consider this in the compiler.
 
Upvote 0
Top