Jump to content

Ternary in AutoIt?


Recommended Posts

Hi,

So far I haven't been able to find the equivelent to a ternary statement in AutoIt. Does one exist?

If not, how do you go about coding something like the following without a windy If-Else-EndIf?:

If $var = 1 Then
   $str = "One"
Else
   $str = "Two"
EndIf

I've been using what feels like a ghetto approach by setting the most "logical" variable first and then conditionally changing it to something else on the next line if need be ala:

$str = "Two" 
If $var = 1 Then $str = "One"

..which knocks the lines way down but seems like horrible practice to set vars bogusly like that.

Any thoughts?

Thanks.

Link to comment
Share on other sites

Hi,

So far I haven't been able to find the equivelent to a ternary statement in AutoIt. Does one exist?

If not, how do you go about coding something like the following without a windy If-Else-EndIf?:

If $var = 1 Then
   $str = "One"
Else
   $str = "Two"
EndIf

I've been using what feels like a ghetto approach by setting the most "logical" variable first and then conditionally changing it to something else on the next line if need be ala:

$str = "Two" 
If $var = 1 Then $str = "One"

..which knocks the lines way down but seems like horrible practice to set vars bogusly like that.

Any thoughts?

Thanks.

Check out the _IIF() function in the Misc.au3 UDF
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...