Skip to main content
1-Visitor
March 22, 2021
Question

If statement only giving second term's value. Works fine for coworkers!!!!

  • March 22, 2021
  • 2 replies
  • 1442 views

I am using a simple if statement, regardless of the value of the defining variable it prints out the second term's value. However, if I give the file to a coworker the if statement works correctly. 

 

 

Unsuccessful things I have tried: 

* Two separate coworkers opened the file and it worked correctly for them without modifying anything

* Changed defining variable to something completely undefined elsewhere. 

* Rebooted my computer.

* Uninstalled v15.05 and reinstalled. 

* Uninstalled v15.05 and installed v14.35.

 

I am loosing my mind. I have no idea what else to do. 

2 replies

23-Emerald V
March 22, 2021

I haven't got Mathcad to hand at the moment, but looking at your images, your "if" statement is incomplete.

 

If the condition is true, Mathcad will calculate the first expression.  However, it will then go straight on to calculate the next expression because you haven't told it to stop processing and return that value.

 

You have a couple of options.

1.  Put a return operator in your "if" expression, so that it looks something like "return <expr1> if <cond>".

2.  Put your second expression in an "otherwise" operator, "expr2 otherwise"

 

Stuart

23-Emerald IV
March 22, 2021

Or you can use the if() function:

LucMeekes_0-1616446785315.png

 

Note that it is always better to attach the Mathcad worksheet.

 

Success!
Luc