Sign in to follow this  
Followers 0
andyswarbs

X=1 .... If X=0 and Z() Then

9 posts in this topic

#1 ·  Posted (edited)

Can I ask fora point of clarification on the following:

Version 1:

$X=1
IF $X=0 and Z() Then
   Exit
Endif

My question "Is the function Z ever evaluated?". This is important since Z may be time-consuming. So a more laborious bit of code but safer, might be:

Version 2:

$X=1
If $X=0 Then
  If Z() Then
    Exit
  Endif
endif

But is the latter necessary? And is Version 1 a happenstance, or (my ideal answer) intentional in the language. I how safe am I in using version 1.

Regards

Andy

Edited by andyswarbs

Share this post


Link to post
Share on other sites



Here are 3 tests I tried. It appears that Z() is never executed if $x does not pass the test.

$X=1
IF $X=0 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    Sleep (5000)
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    Sleep (5000)
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    Sleep (5000)
    Return 0
EndFunc

MsgBox (0, "exiting", "normally")

Share this post


Link to post
Share on other sites

Here are 3 tests I tried. It appears that Z() is never executed if $x does not pass the test.

$X=1
IF $X=0 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    Sleep (5000)
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    Sleep (5000)
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    Sleep (5000)
    Return 0
EndFunc

MsgBox (0, "exiting", "normally")
there is a difference in z and Z

if you try it with z() instead of Z() you will get inside the function

$x = 0
if $x = 1 and z() then
...
endif

won't get inside the function

so its up to you to choose how you write your code

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

there is a difference in z and Z

if you try it with z() instead of Z() you will get inside the function

$x = 0
if $x = 1 and z() then
...
endif

won't get inside the function

so its up to you to choose how you write your code

I'm not sure I understand what you mean a difference between Z() and z() in this post:
MsgBox(0, '', Z())
Func z()
    Return 5
EndFunc

MsgBox(0, '', y())
Func Y()
    Return 6
EndFunc

Edit:

Or even trying to reitterate that it does reach Z()... or z() ... $x obviously = 0 but Z() obviously would return 5, so if one of the 2 are true then it should give you the msgbox:

$x = 0
If $x = 1 Or Z() = 5 Then MsgBox(0, 'Done', 'Reached Z() and it = ' & Z())
Func z()
    Return 5
EndFunc
Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Can I ask fora point of clarification on the following:

Version 1:

$X=1
IF $X=0 and Z() Then
   Exit
Endif

My question "Is the function Z ever evaluated?".

No Z() isn't evaluated.

Share this post


Link to post
Share on other sites

there is a difference in z and Z

if you try it with z() instead of Z() you will get inside the function

$x = 0
if $x = 1 and z() then
...
endif

won't get inside the function

so its up to you to choose how you write your code

Did you try it? It doesn't matter if it's small z or big z.

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    MsgBox (0, "in z", "z = Z")
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

I definitely got in z() there.

Plus, if you use z() and Z() (which according to you would be different), you get this error:

ERROR: Z() already defined.

Func Z()

~~~~~~~~^

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    MsgBox (0, "in z", "z = Z")
    Return 1
EndFunc

Func Z()
    MsgBox (0, "in big Z", "wtf")
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

This shows that AutoIt considers z() and Z() to be the same function, and this makes perfect sense since it's not case-sensitive.

Share this post


Link to post
Share on other sites

Did you try it? It doesn't matter if it's small z or big z.

$X=1
IF $X=1 and Z() Then
    MsgBox (0, "in func", "whee")
   Exit
Endif

Func z()
    MsgBox (0, "in z", "z = Z")
    Return 1
EndFunc

MsgBox (0, "exiting", "normally")

I definitely got in z() there.

Plus, if you use z() and Z() (which according to you would be different), you get this error:

$X=0 ; this one will not go to z() because $x = 0

IF $X=1 and Z() Then

MsgBox (0, "in func", "whee")

Exit

Endif

Your example shows $x = 1 as true which it is, so then it goes to Z(). Now if $x = 0 then it is false, so it never goes to Z() because the first inquiry isn't true so there is no need to go to z().

[center]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.[/center]

Share this post


Link to post
Share on other sites

A quote from myself when I first posted: Z() is never executed if $x does not pass the test.

What I was showing in my last post is that when $x passes (and the script goes on to check z()), it doesn't matter if the functions match case or not. z() = Z(). That's all I'm saying.

I made $x = 1 on purpose the second time around, so that I knew it would be going to Z(). I was hoping everyone would understand that the different tests were done on purpose....

Share this post


Link to post
Share on other sites

A quote from myself when I first posted: Z() is never executed if $x does not pass the test.

What I was showing in my last post is that when $x passes (and the script goes on to check z()), it doesn't matter if the functions match case or not. z() = Z(). That's all I'm saying.

I made $x = 1 on purpose the second time around, so that I knew it would be going to Z(). I was hoping everyone would understand that the different tests were done on purpose....

I understood, I was reitterating your post :o.

[center]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.[/center]

Share this post


Link to post
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
Sign in to follow this  
Followers 0