Page 1 of 1

[SOLVED] Simple logic problem

Posted: Sat Apr 24, 2010 8:14 am
by avatar
I need help here.
I am confused with this procedure which always returns "False"

Code: Select all

Procedure.l iff(test.l, iftrue.l, iffalse.l)
  If (test)
    ProcedureReturn iftrue
  Else
    ProcedureReturn iffalse
  EndIf
EndProcedure
testvar = 80
Debug Str(iff(testvar<=0,100,200))
Debug Str(iff(testvar>0,100,200))

Re: Simple logic problem

Posted: Sat Apr 24, 2010 9:32 am
by Trond
You can't use operators like <= and > in normal expression. They can only be used with conditional expressions, such as If and While.

Re: Simple logic problem

Posted: Mon Apr 26, 2010 6:34 am
by idle
you will need to use a series of macros with matching procedures if you want to do a ternary if.
there's a solution in this thread

http://www.purebasic.fr/english/viewtop ... f&start=30

Code: Select all


Procedure.i IIFEvali(expr,y,n)
If expr
  ProcedureReturn y
Else
  ProcedureReturn n
EndIf
EndProcedure

Macro IFF(expr,y,n)
IIFEvali((Not(expr)),n,y)
EndMacro


testvar.i = 80
Debug Str(iff(testvar<=0,100,200))
Debug Str(iff(testvar>0,100,200))

Re: Simple logic problem

Posted: Mon Apr 26, 2010 6:55 am
by avatar
Thanks idle, very tricky!