Jump to content

Using "and" in an "if" statement


---
 Share

Recommended Posts

Is using an "and" in a "if" statement possible?

Point1_Z_value_LE=getActual("Point1").z
Point2_Z_value_LE=getActual("Point2").z
Point3_Z_value_LE=getActual("Point3").z
Point1_Z_value_LE_abs=abs(getActual("Point1").z-0.415)
Point2_Z_value_LE_abs=abs(getActual("Point2").z-0.415)
Point3_Z_value_LE_abs=abs(getActual("Point3").z-0.415)
if Point1_Z_value_LE_abs>Point2_Z_value_LE_abs and Point1_Z_value_LE_abs>Point3_Z_value_LE_abs then
MAXDev_LE=Point1_Z_value_LE
endif
if Point2_Z_value_LE_abs>Point1_Z_value_LE_abs and Point2_Z_value_LE_abs>Point3_Z_value_LE_abs then
MAXDev_LE=Point2_Z_value_LE
endif
if Point3_Z_value_LE_abs>Point1_Z_value_LE_abs and Point3_Z_value_LE_abs>Point2_Z_value_LE_abs then
MAXDev_LE=Point3_Z_value_LE
endif
Link to comment
Share on other sites

In my experience that doesn't always work. The safe way is a separate statement:
...
if Point1_Z_value_LE_abs>Point2_Z_value_LE_abs then
MAXDev_LE=Point1_Z_value_LE
endif
if Point1_Z_value_LE_abs>Point3_Z_value_LE_abs then
MAXDev_LE=Point1_Z_value_LE
endif
...
Link to comment
Share on other sites

You need to isolate the precedence of the boolean expressions from the if-statement.
In english:
if (a < b) and (d > c)
	display("Joey Buttafucko")
endif
Link to comment
Share on other sites

Please sign in to view this quote.

Hahahaha, I'm educated by you.. 😉
Well, I should have said, you have to force precedence of the boolean expression before the if-statement everytime "and" or "or" is included 🙂

I'm pretty useless at English. Guess I was more intrested in beer and tits in school. 🙄
Link to comment
Share on other sites

Have you noticed this?:

a=1
b=2
c=3
d=4

///// no error:
if a < b and d > c then
	display("True")
else
	display("False")
endif


if a < b and d < c then
	display("True")
else
	display("False")
endif


//////// syntaxis error when first condition is false:
if a > b and d < c then
	display("True")
else
	display("False")
endif


if a > b and d > c then
	display("True")
else
	display("False")
endif
Link to comment
Share on other sites

 Share

×
×
  • Create New...