![]() |
|
[AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf (/Thread-AutoIt-If-Else-ElseIf-Not-Or-Then-EndIf) |
[AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - 1234hotmaster - 09-25-2011 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 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 ) RE: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - thRain - 04-28-2012 Thanks for the tutorial with If and the = >< etc. However I'm still quite confused with endif, what's the point of adding it ? I understand "elseif" though. RE: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - thRain - 04-28-2012 Thanks for the tutorial with If and the = >< etc. However I'm still quite confused with endif, what's the point of adding it ? I understand "elseif" though. RE: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - Jacob - 04-28-2012 EndIf is 100% mandatory if you have a multi line IF Statement. For example; this code does NOT need and EndIf because it is NOT mutli line. Code: local $i = 1, $x=5
If $i <= $x then ConsoleWrite("Variable X is greater than variable i")But this statement does because it IS multi line. Code: Local $i = 1, $x = 5
If $i <= $x Then
ConsoleWrite("Variable X is greater than variable i")
$i = $i + 4
$x = $x - 4
ElseIf $i <= $x Then
ConsoleWrite("Variable X is greater than variable i")
Else
ConsoleWrite("Sucks for you")
EndIfRE: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - Jacob - 04-28-2012 EndIf is 100% mandatory if you have a multi line IF Statement. For example; this code does NOT need and EndIf because it is NOT mutli line. Code: local $i = 1, $x=5
If $i <= $x then ConsoleWrite("Variable X is greater than variable i")But this statement does because it IS multi line. Code: Local $i = 1, $x = 5
If $i <= $x Then
ConsoleWrite("Variable X is greater than variable i")
$i = $i + 4
$x = $x - 4
ElseIf $i <= $x Then
ConsoleWrite("Variable X is greater than variable i")
Else
ConsoleWrite("Sucks for you")
EndIfRE: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - cOd3r - 04-20-2014 Nice tut bro..thnks.. RE: [AutoIt]If - Else - ElseIf - Not - Or - Then - EndIf - cOd3r - 04-20-2014 Nice tut bro..thnks.. |