Page 1 of 1
The IIF function
Posted: Thu Jul 24, 2025 9:50 pm
by bds107
Hi everyone!
Back when animals still spoke, there was something called IIF. Unfortunately, it wasn't built into PureBASIC, or I'd have to cross my eyes.
Code: Select all
GLOBAL result.s, userInput.a
result.s = IIF(userInput MOD 2 = 0, "Even", "Odd")
DEBUG "The number is " + result
Hopefully...
Re: The IIF function
Posted: Thu Jul 24, 2025 10:36 pm
by Quin
This has been requested many times. I've concluded that it'll never happen.
PB isn't a bad language for pounding out a native executable that works across operating systems. But if you want anything even close to modern syntax, it's not it. I personally recommend Crystal for that.
Re: The IIF function
Posted: Thu Jul 24, 2025 10:54 pm
by AZJIO
PureAutoIt
Code: Select all
Macro IIf(expr, truepart, falsepart=__expr_null__.b)
If expr
truepart
Else
falsepart
EndIf
EndMacro
bds107 wrote: Thu Jul 24, 2025 9:50 pm
Code: Select all
result.s = IIF(userInput MOD 2 = 0, "Even", "Odd")
Re: The IIF function
Posted: Thu Jul 24, 2025 11:01 pm
by Quin
AZJIO wrote: Thu Jul 24, 2025 10:54 pm
PureAutoIt
Code: Select all
Macro IIf(expr, truepart, falsepart=__expr_null__.b)
If expr
truepart
Else
falsepart
EndIf
EndMacro
Only works in super basic cases. I can't do this for example:
Code: Select all
MessageRequester("Current score is", Str(Points) + " " + Iif(Points = 1, "point", "points"))
That's why I'd like it to be a language feature, not a new function. But we know how Fred feels about those.
Re: The IIF function
Posted: Thu Jul 24, 2025 11:07 pm
by AZJIO
Code: Select all
Procedure.s IIF(expr, truepart.s, falsepart.s)
If expr
ProcedureReturn truepart
Else
ProcedureReturn falsepart
EndIf
EndProcedure
Global result.s, userInput.a = 1
result.s = IIF(userInput & 1, "Odd", "Even")
Debug "The number is " + result
Global Points = 1
MessageRequester("Current score is", Str(Points) + " " + Iif(Bool(Points = 1), "point", "points"))