If and or expression Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

If and or expression

Post by arpit12 » 19 May 2022, 10:38

Hi,
i trying to put or statement in IF statement but its not working.

Code: Select all

Loop, Files, %dir%\*.*
{ 
	SplitPath, A_LoopFilePath, fn,, ext
	part := StrSplit(fn, "_")
If (part.1 != "abc" ) || (part.1 != "aaa" )

what i am doing wrong?

braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: If and or expression

Post by braunbaer » 19 May 2022, 11:05

This expression will always return true, because part.1 can't be at the same time equal to "abc" and to "aaa" , so at least one subexpression on one side of the or must be true.

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: If and or expression

Post by arpit12 » 19 May 2022, 11:20

ok so what should i do if i want to exclude these 2 in IF statement. basically i want the IF statement to run only when it is not equals to abc or aaa what should be the right way to do that.

User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: If and or expression  Topic is solved

Post by boiler » 19 May 2022, 11:26

arpit12 wrote: basically i want the IF statement to run only when it is not equals to abc or aaa what should be the right way to do that.
You're not stating it right, which is why your code isn't correct. You want it to run when it is not equal to abc and it is not equal to aaa. So change the || to &&. Re-read what braunbaer said as to why your logic is wrong in how you stated it in English.

Or you can change it to "equal" conditions and leave it as "or" and put the "not condition" outside of the pair of conditions. That's probably closer to how you're thinking about it in your mind:

Code: Select all

If !((part.1 = "abc" ) || (part.1 = "aaa" ))
...which says part.1 is not equal to abc or aaa.

arpit12
Posts: 56
Joined: 10 Apr 2022, 04:19

Re: If and or expression

Post by arpit12 » 19 May 2022, 11:44

Thanks it works

Post Reply

Return to “Ask for Help (v1)”