[SOLVED] Simple logic problem

Just starting out? Need help? Post your questions and find answers here.
avatar
User
User
Posts: 35
Joined: Fri Apr 16, 2010 11:43 am

[SOLVED] Simple logic problem

Post 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))
Last edited by avatar on Mon Apr 26, 2010 6:55 am, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Simple logic problem

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 5984
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Simple logic problem

Post 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))
avatar
User
User
Posts: 35
Joined: Fri Apr 16, 2010 11:43 am

Re: Simple logic problem

Post by avatar »

Thanks idle, very tricky!
Post Reply