Jump to content

Recommended Posts

Posted

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.

Posted

If more than 2 options it's belong to a Select...Case struct or maybe Switch $Something...Case and putting the ElseIf as Case Else. It's also much better because you can use range or falling through.

Posted

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

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
×
×
  • Create New...