# IF statement usage

## Recommended Posts

Can you use an if statement this way:

If \$var1 = "1" or '2" or "3" Then

msgbox(0,"info", "You used one, two or three")

EndIf

Or is a case statement like this required for more than three variables?

Case \$var1 = "1"

msgbox(0,"info", "You used one, two or three")

Case \$var1 = "2"

msgbox(0,"info", "You used one, two or three")

Case \$var= "3"

msgbox(0,"info", "You used one, two or three")

EndSelect

Me

Edited by IvanCodin

##### Share on other sites

I had better luck with the case...

```http://www.autoitscript.com/forum/index.php?app=forums&module=post&section=post&do=reply_post&f=2&t=103096&qpid=730789

Select
Case \$var1 = "1"
msgbox(0,"info", "You used one")
Case \$var1 = "2"
msgbox(0,"info", "You used two")
Case \$var1 = "3"
msgbox(0,"info", "You used three")
EndSelect```

But you should be able to do both

```If \$var1 = "1"
msgbox(0,"info", "You used one")

ElseIf \$var1 = "2" Then
msgbox(0,"info", "You used two")
Else \$var1 = "3"
msgbox(0,"info", "You used three")

EndIf```

##### Share on other sites

Hi,

```\$var1 = 2

If \$var1 = 1 or \$var1 = 2 or \$var1 = 3 Then msgbox(0,"info", \$var1)

;Or
Switch \$var1
Case 1,2,3
msgbox(0,"info", \$var1)
EndSwitch

;Or
Switch \$var1
Case 1 To 3
msgbox(0,"info", \$var1)
EndSwitch

;Or
Switch \$var1
Case 1
msgbox(0,"info", \$var1)
Case 2
msgbox(0,"info", \$var1)
Case 3
msgbox(0,"info", \$var1)
EndSwitch

;Or
Select
Case \$var1 = 1 Or \$var1 = 2 Or \$var1 = 3
msgbox(0,"info", \$var1)
EndSelect

;Or
Select
Case \$var1 > 0 And \$var1 < 4
msgbox(0,"info", \$var1)
EndSelect

;Or
Select
Case \$var1 = 1
msgbox(0,"info", \$var1)
Case \$var1 = 2
msgbox(0,"info", \$var1)
Case \$var1 = 3
msgbox(0,"info", \$var1)
EndSelect

; All do the same thing
; there's quite a lot of ways more to do the same thing
; Just depends on your needs and preference.```

Cheers

##### Share on other sites

Thanks!! It didn't error when I used syntaxcheck but I didn't find anything in thr help file for the if \$var1 = '1" or "2" bla bla

Me

##### Share on other sites

Try

```If \$var1 = "1" or \$var1 = "2" or \$var = "3" Then
Blah```

My ProgramsMy WIP'sSteam Server Restarter

## Create an account

Register a new account