always. stay consistent, avoid any issues (it's a common issue for a noob to not use () and simply adding them solves the issue), save work later on if you need to add other stuff with && or || or if you prefer the { on the same line as the if/while/etc (OTB style)
if (GetKeyState("a", "P"))
though, with some functions like getkeystate, fileexist, and others, I do not always include an "=1" or "=0" (as I mentioned earlier that I always add them). the names make it obvous when reading.
"if the file exists..." is perfectly readable.
"if the file exists=1..." just looks silly
! or 'not' to validate an expression in an if statement as false? Topic is solved
Re: ! or 'not' to validate an expression in an if statement as false?
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
*poke*
Is it December 21, 2012 yet?
Re: ! or 'not' to validate an expression in an if statement as false?
Interesting. How about an expression with several parentheses like this: (A_Index > 1) || (A_Index = 1 && !current_ip != ""). Would you put this as a whole in parentheses as well when used with an if statement? So if ((A_Index > 1) || (A_Index = 1 && !current_ip != ""))
Greetings Leli196
Greetings Leli196
Re: ! or 'not' to validate an expression in an if statement as false?
like my example on the previous page. if (EVERYTHING)
if (var)
if (var && var2 || func())
if ((var3 || var) && var2)
not a bunch of ()'s like some people prefer: if (var) || (var2+5) || (func()-1)
if (var)
if (var && var2 || func())
if ((var3 || var) && var2)
not a bunch of ()'s like some people prefer: if (var) || (var2+5) || (func()-1)
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
*poke*
Is it December 21, 2012 yet?
Re: ! or 'not' to validate an expression in an if statement as false?
From what I tested, () isn't always a good idea. Here it is:tidbit wrote:Always. Stay consistent, avoid any issues (it's a common issue for a noob to not use () and simply adding them solves the issue).
Code: Select all
; Works correctly
var := "aaa"
if var contains foo,bar,baz
msgBox % "Success"
; As I understand, parentheses are illegal here
var := "aaa"
if (var contains foo,bar,baz)
msgBox % "Success"
Re: ! or 'not' to validate an expression in an if statement as false?
Yeah you are on to something however you got it backwards.
NEVER USE CONTAINS.
NEVER USE CONTAINS.
Recommends AHK Studio
Re: ! or 'not' to validate an expression in an if statement as false?
@nnnik
1. Why we should avoid it?
2. Do you suggest to use inStr() or regExMatch() instead?
3. Also, do you suggest to avoid if var in and if var between as well?
Thanks. But there are some questions from my side:nnnik wrote:Yeah you are on to something however you got it backwards.
NEVER USE CONTAINS.
1. Why we should avoid it?
2. Do you suggest to use inStr() or regExMatch() instead?
Code: Select all
var := "foo"
if inStr(var, "foo") || inStr(var, "bar")
msgBox % "Success"
var := "foo"
if regExMatch(var, "(foo|bar)")
msgBox % "Success"
Re: ! or 'not' to validate an expression in an if statement as false?
Yeah they are not expressions and are inconsistent with expression syntax - due to that they are not an option.
Sadly there is not a simple alternative available - depending on who you ask there might be several answers:
Depending onthe circumstances different answers might be better
Sadly there is not a simple alternative available - depending on who you ask there might be several answers:
Code: Select all
isDay := { moday:1, tuesday:1, wednesday:1, thursday:1, friday:1, saturday:1, sunday:1 }
if ( isDay[ day ] )
Msgbox % day " is the name for a day"
Recommends AHK Studio
Re: ! or 'not' to validate an expression in an if statement as false?
@nnnik Thanks. Now there is another good option.
Re: ! or 'not' to validate an expression in an if statement as false? Topic is solved
also, the "if var in/contains/type" style if's are on a separate page than normal if's for a reason: they are different than normal if's.
they are not expressions, cannot use (), cannot use with || && and so on. they need to be EXACTLY as documented on their own page, not as documented on some other page (normal if's).
(same goes for hotkeys and send. so many people try to do {enter}:: or w/e. why? SEND docs are a completed different page than hotkey docs. stick with the correct page, folks! You wouldn't go read a monster trucks manual to fix a moped.)
they are not expressions, cannot use (), cannot use with || && and so on. they need to be EXACTLY as documented on their own page, not as documented on some other page (normal if's).
(same goes for hotkeys and send. so many people try to do {enter}:: or w/e. why? SEND docs are a completed different page than hotkey docs. stick with the correct page, folks! You wouldn't go read a monster trucks manual to fix a moped.)
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
*poke*
Is it December 21, 2012 yet?
Re: ! or 'not' to validate an expression in an if statement as false?
Don't you think perhaps a warning would be in order on those pages, so that people won't mix together two incompatible modes? I believe "if"* does contain some nice warnings about the brackets and expression mode, but I don't know about thetidbit wrote:also, the "if var in/contains/type" style if's are on a separate page than normal if's for a reason: they are different than normal if's.
they are not expressions, cannot use (), cannot use with || && and so on. they need to be EXACTLY as documented on their own page, not as documented on some other page (normal if's).
(same goes for hotkeys and send. so many people try to do {enter}:: or w/e. why? SEND docs are a completed different page than hotkey docs. stick with the correct page, folks! You wouldn't go read a monster trucks manual to fix a moped.)
"contains" page or section (or wherever that term is described).
Return to “Off-topic Discussion”
Who is online
Users browsing this forum: No registered users and 40 guests