Android Question Conditional operator logic

Genricke

Member
Hi !
Simple example: compiles and runs - no problem !

B4X:
Sub EasyTest
    If 2 = 2 Then
        Log(1)
        If      3 = 5  Then Log("One")
        else If 4 = 4  Then Log("Two")
        Log(3)
    End If
End Sub

Waiting: 1 -> Two -> 3
Reality: 1
Why ?! Thanks ! :)
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The IDE marks the condition block:

1617945627852.png

I think that it explains the flow.

Correct code to get the result you expect:

B4X:
Sub EasyTest
    If 2 = 2 Then
        Log(1)
        If 3 = 5 Then
            Log("One")
        Else If 4 = 4  Then 
            Log("Two")
        End If
        Log(3)
    End If
End Sub
 
Upvote 0
Top