[AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf 09-25-2011, 08:13 PM
#1
The "If" Statement is used in almost ALL programming and scripting languages. Its for making decisions like changing the code depending on the situation. It uses Comparison and Logical operators.
Comparison Operators
= - Equal to
== - Case Sensetive Equal to
<> - Not equal to
> - Bigger than
< - Lower than
=> - Bigger or equal to
=< - Lower or equal to
Logical operators
And
Not
Or
Ok lets start
or it can be like this:
it will show the messagebox if the case is "True". $var1 is not equal to $var2 so it will return "False" and the msgbox will not trigger. To make it show a msgbox on both situations you can:
Another way of a more than 2 situation "If" statement can be:
using "Else" with "ElseIf":
Not is used for Equal to False. By normal "If" statement is equal to True. Like
We can use not to make sure its empty
so:
is the same as
We use Not to make our code look neater and cooler :whistle: and more understandable :yes: just remember it must be used before the variables.
Will not work:nono:
Now let move on to "Or"
It can be used to make sure one of two or more statements is equal to true instead of lots of ElseIf's.
Last but not least, "And".
Its used for making sure more than 1 statements match your requirements and both must return True.
well we are done and you can come up with your own code just by looking at the examples
but there is something, Like if there is 1 statement in a If statement you can type it in front of Then otherwise you can enter it in the next line and in the line after all your statements add a "EndIf".
If there is any questions feel free to ask
For more info read the help file ( F1 when in SciTe )
Comparison Operators
= - Equal to
== - Case Sensetive Equal to
<> - Not equal to
> - Bigger than
< - Lower than
=> - Bigger or equal to
=< - Lower or equal to
Logical operators
And
Not
Or
Ok lets start
Code:
$var1 = "Black"
$var2 = "White"
If $var1 = $var2 Then MsgBox(64,"Info","They Match")Code:
$int1 = 66
$int2 = 434
If $int1 > $int2 then msgbox(64,"","$int1 is bigger than $int2")or it can be like this:
Code:
$var1 = "Black"
$var2 = "White"
If $var1 = $var2 Then
MsgBox(64,"Info","They Match")
EndIfit will show the messagebox if the case is "True". $var1 is not equal to $var2 so it will return "False" and the msgbox will not trigger. To make it show a msgbox on both situations you can:
Code:
$var1 = "Black"
$var2 = "White"
If $var1 = $var2 then
msgbox(64,"Info","They Match")
Else ; OtherWise
msgbox(16,"Info","They Don't Match")
EndifAnother way of a more than 2 situation "If" statement can be:
Code:
$var1 = "Black"
$var2 = "White"
If $var1 = $var2 then
msgbox(64,"Info","They Match")
elseif $var1 <> $var2 then
msgbox(16,"Info","They Don't Match")
elseif $var1 = "Gray" then
msgbox(16,"Info","$var1 is gray!!!")
endifusing "Else" with "ElseIf":
Code:
$var1 = "Black"
$var2 = "White"
If $var1 = $var2 then
msgbox(64,"Info","They Match")
elseif $var1 <> $var2 then
msgbox(16,"Info","They Don't Match")
elseif $var1 = "Gray" then
msgbox(16,"Info","$var1 is gray!!!")
else
msgbox(16,"Info","Non of the above matches")
endifNot is used for Equal to False. By normal "If" statement is equal to True. Like
Code:
Dim $var
If $var Then Msgbox(64,"","$var is not empty")We can use not to make sure its empty
so:
Code:
Dim $var
If Not $var then msgbox(64,"","$var is empty")Code:
Dim $var
If $var = False then msgbox(64,"","$var is empty")We use Not to make our code look neater and cooler :whistle: and more understandable :yes: just remember it must be used before the variables.
Code:
If $var Not thenNow let move on to "Or"
It can be used to make sure one of two or more statements is equal to true instead of lots of ElseIf's.
Code:
$var1 = "Black"
$var2 = "White"
If $var1 = $var2 or $var1 = "Black" Then msgbox(64,"","One or both of the requirement matched.")Last but not least, "And".
Its used for making sure more than 1 statements match your requirements and both must return True.
Code:
$var1 = "Black"
$var2 = "White"
if $var1 = "Black" And $var2 = "White" then msgbox(64,"","Everything is ok both of the $var values are correct")well we are done and you can come up with your own code just by looking at the examples

but there is something, Like if there is 1 statement in a If statement you can type it in front of Then otherwise you can enter it in the next line and in the line after all your statements add a "EndIf".
If there is any questions feel free to ask

For more info read the help file ( F1 when in SciTe )
Pierce the life fibers with your drill.




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)