Sign in to follow this  
Followers 0
jhbell

Change in IF.. Then Statement Syntax ??

9 posts in this topic

Change in IF.. Then Statement Syntax ??

I think this is more a develoment issue than a bug:

Using released version of V3 the following works fine:

If $var1 = value then if $var2 = value then $var3 = value

It is also valid Syntax per : If <expression> Then statement

In beta version installed today I get:

----------------------------------------------------------------

If $var1 = value then if $var2 = value then $var3 = value

If $var1 = value then ^ ERROR

Error: This keyword cannot be used after a "Then" keyword.

----------------------------------------------------------------

I appreciate that better code would have used "and" but that is

not the point... I think exceptions like this make a language hard to

learn/remember/use and document. eg:

If <expression> Then statement

EXCEPT that statement cannot be .....

Kinda like "i after e except when followed by or preceeded by..." :ph34r:

I will now go and correct my poor V3 code but beware the wrath

of dumb and dirty coders when you release the beta!

PS: To verify this I switched back and forth between old and new versions

by renaming the new and old versions of autoitV3.exe in Program files. Surely there

is a better way af compatibility testing... can SciTe be set up with one button for

new and one for old? Appreciate any input you guys have on a better way.

Share this post


Link to post
Share on other sites



Just use this instead:

If $var = 1 Then
  If $other_var = 1 Then Do_My_Func()
EndIf

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Ah yes! So the documentation should read:

#cs

If statement syntax can be confusing:

Remember that in the form:

If <expression> Then statement

that the statement may not be another if statement.

however in the form:

If <expression> Then

statements

EndIf

that the statements may be other if statements

unless of course they are of the form

If <expression> Then statement

in which case statement may not be another if statement!

#ce

Its all clear to me now. :ph34r:

Time for bed!

Share this post


Link to post
Share on other sites

It is slightly ackward, but you should never need to do this, because if you have two If statements that would be executed right after one another, you can combine them with AND or OR. This is true because the compiler is smart enough to stop testing the conditional statement if it knows it's false from the part it's already calculated.

For example, let $a = 0 and consider the following line of code:

If $a AND MsgBox(4, "PICK", "Pick an option please") = 7 Then Exit

In that line of code, you will never see the Message Box, even though it is part of the conditional statement. That is because $a was 0, and the program exited before it displayed the message box since there was no need to get that result.

However, if $a was 1 in the above example, then you would see the message box.

My whole point is that there should never be a need to use that syntax you posted above that gave you an error. If you want to use it anyway, you'll have to use the form I posted in my first reply.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

The "If ... Then ... If" thing should never have been allowed and has been removed as a bug fix in the beta. Allowing it makes checking for block structures in the code much more messy (i.e. the internal code that checks for missing EndIfs and determining whether an If statement is a single line type or a block type)

Share this post


Link to post
Share on other sites

May I suggest then that you change the help file to the following:

----CHANGES IN CAPS----

If...Then

--------------------------------------------------------------------------------

Conditionally run a single statement.

If <expression> Then NON-CONDITIONAL-STATEMENT

Parameters

expression If the expression is true, the statement is executed.

Remarks

This version of the If statement is used to execute a single statement without the overhead of an EndIf.

THE STATEMENT HOWEVER MUST BE NON-CONDITIONAL. IE:- IT MAY NOT BE AN IF OR WHILE STATEMENT.

The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed.

Share this post


Link to post
Share on other sites

The "If ... Then ... If" thing should never have been allowed and has been removed as a bug fix in the beta.  Allowing it makes checking for block structures in the code much more messy (i.e. the internal code that checks for missing EndIfs and determining whether an If statement is a single line type or a block type)

I agree with Jon. It's bad/messy syntax, but I discovered Visual Basic does allow statements like If 1=1 Then If 2=2 Then MsgBox(0,"","foo")

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

I agree with Jon. It's bad/messy syntax, but I discovered Visual Basic does allow statements like If 1=1 Then If 2=2 Then MsgBox(0,"","foo")

Most languages do, but Jon did say it's a lot harder to code in terms of the C++ sources. I also don't see why this is even an issue. There should never be a need to chain If statements together like that. If you have some code that uses that method, you can split it up with proper use of AND or OR blocks (and parentheeses as required.)

It might be nice to be able to chain them together, but it's really not that hard to use one of the 2 avaiable alternatives.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

My original issue was not so much wanting to do it this way, but rather messing up the language definition with these exception rules. If we accept that this one line IF is an exception to avoid Endif for convenience, then I'd go along with the non-conditional statement change above.

I had thought that the interpreter could handle the second IF by simply treating it as an 'AND' but I couldn't figure out what it should do on If a=1 Then While B<5

Will someone update the Help File?

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