# If ... else

#### colin9876

##### Active Member
Licensed User
Really Basic BASIC question

why doesnt this code work
if n=0 then msgbox("No")
else msgbox("yes")

The if part works on its own but ive somehow got the else condition wrong because it doesnt work when I add that part?

Also if I want to do 2 things after an if how do I combine them so it does both on condition of that if?
e.g if n=0 then msgbox("No")
and x=1

#### petrbury

##### Member
Licensed User
Hi,
try

If n=0 Then
Msgbox("No")
Else
Msgbox("yes")
End If

it should work.

The second question :

If condition Then
action1
action2
.
.
actionx
End If

Regards
Petr

#### Erel

##### Administrator
Staff member
Licensed User
There are two syntaxes:
B4X:
``If n = 0 then msgbox("No") else msgbox("yes")   'Single line``
or:
B4X:
``````If n=0 then
msgbox("no")
...
else if n = 1 then
...
else if ... then
...
else
...
end if``````

#### colin9876

##### Active Member
Licensed User
Thanks - very helpful.
I see it was because I had the IF ELSE over two lines that it didnt work - much appreciated