Jump to content

help with if..and..or


Recommended Posts

Hello everyone again,

I have some conditions to be processed by my program:

Consider four conditions A,B,C,D each of which can have value either TRUE or FALSE decided by other parameters.

now, I have to include an If..Then..EndIf condition as following:

if A and B are both TRUE or C and D are both true ( or obviously all four are true )..

Then...if I write like the following, will it work according to its syntax ?

if ($a=true and $b=true) or ($c=true and $d=true) then
[some lines]
endif

It doesnt give any error as such during its compiling..but do the brackets make the program 'understand' what my real condition is ?

Thanks.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

Worked !

But I wanted some confirmation from you great MVP and DEV guys that our marvelous autoit language supports some complex conditions with such brackets in them.. :)

Edited by Shaarad
Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

That is written properly but just to clarify your

( or obviously all four are true ).

It will never check if all four conditions are True. As soon as the first set of conditions is met it will stop there without any further checking because of the OR.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

OK agree with you GEOSoft, but I just wrote this experimental code:

$var1=True
$var2=False
$result=False
if (not ($var1=true and $var2=True)) or ($var1=false and $var2=true) or ($var1=true and $var2=false) then
    $result=True
EndIf
msgbox (0,"",$result)

and the msgbox still returns the value as 'False' and not 'True' as expected..

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

the brackets are wrong placed in that example. also you dont need to put the =true or the =false. and using OR means If ANY of the different conditions is true( or false if you use NOT)then..

It seems that it work that way too.. :)

Edited by monoscout999
Link to comment
Share on other sites

You posted code returns true as expected because this is true: (not ($var1=true and $var2=True))

But I get the msgbox mentioning 'False'...

sorry didn't get your point

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

To monoscout999,

As in my code, I have mentioned the the last condition which is true. Hence, according to my knowledge, the if ..endif condition is satisfied and the $result should now attain the value as True from its previous value False.

But, it doesnot attain this and still giving the value as False only.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

;);):D

It actually WAS giving the value as False...but I had copied the code from my editor and pasted it here...and now when I read your replies, I copied the code from HERE and pasted it in my editor..and now it IS giving the value as true...

How can it be possible ? :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

  • Developers

;);):D

It actually WAS giving the value as False...but I had copied the code from my editor and pasted it here...and now when I read your replies, I copied the code from HERE and pasted it in my editor..and now it IS giving the value as true...

How can it be possible ? :)

Well, as I do not believe in miracles, there must be a difference between the code you tested with before and what is posted.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It may be because I didn't save the changes in the code and it kept on running the code without my changes :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

If you use SciTe the undo will do magic, i don´t know how many times you can do it, but it saves me a lot of times when i start to write in an existing file without noticed and when i run the script SciTe Saves the file overwriting the existing. about your first post.

Hello everyone again,

I have some conditions to be processed by my program:

Consider four conditions A,B,C,D each of which can have value either TRUE or FALSE decided by other parameters.

now, I have to include an If..Then..EndIf condition as following:

if A and B are both TRUE or C and D are both true ( or obviously all four are true )..

Then...if I write like the following, will it work according to its syntax ?

check first If All the variables are true, and later do the check for the groups, is important the order of the conditions to check if you use "OR".

Correct way.

$var1=True
$var2=False
$var3=True
$var4=True
$result=False
if ($var1 and $var2 and $var3 and $var4) or ($var1 and $var2) or ($var3 and $var4) then
    $result=True
EndIf
msgbox (0,"",$result)

Incorrect way.

$var1=True
$var2=False
$var3=True
$var4=True
$result=False
if ($var1 and $var2) or ($var3 and $var4) or ($var1 and $var2 and $var3 and $var4) then
    $result=True
EndIf
msgbox (0,"",$result)
Link to comment
Share on other sites

Thanks a lot monoscout999 for providing such an elaborated explanations about the things which look simple, but have a deep meaning which must be considered to avoid confusions.

Thanks again ! :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Link to comment
Share on other sites

If you use SciTe the undo will do magic, i don´t know how many times you can do it, but it saves me a lot of times when i start to write in an existing file without noticed and when i run the script SciTe Saves the file overwriting the existing. about your first post.

check first If All the variables are true, and later do the check for the groups, is important the order of the conditions to check if you use "OR".

Correct way.

$var1=True
$var2=False
$var3=True
$var4=True
$result=False
if ($var1 and $var2 and $var3 and $var4) or ($var1 and $var2) or ($var3 and $var4) then
    $result=True
EndIf
msgbox (0,"",$result)

Incorrect way.

$var1=True
$var2=False
$var3=True
$var4=True
$result=False
if ($var1 and $var2) or ($var3 and $var4) or ($var1 and $var2 and $var3 and $var4) then
    $result=True
EndIf
msgbox (0,"",$result)

I'm confused. Logically wouldn't just this be sufficient?

if ($var1 and $var2) or ($var3 and $var4) then
    $result=True
EndIf
msgbox (0,"",$result)[/autoit]

When would this statement ever be false and this statement true: ($var1 and $var2 and $var3 and $var4)?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...