Operators > Programming Operators > Conditional Operators
Conditional Operators
Evaluates y when x is nonzero (true). The if operator opens conditional statements.
Evaluates y when x is nonzero (true). This happens only when the preceding if or elseif statements are zero (false).
You can only write an elseif statement directly after an elseif or an if statement.
Evaluates y when x is nonzero (true). This happens regardless of whether the preceding if or alsoif statements are zero (false) or nonzero (true).
You can only write an alsoif statement directly after an alsoif or an if statement.
You cannot use the alsoif and elseif statements together in the same if statement.
Evaluates y when the preceding statements are zero (false). The else operator closes conditional statements.
You can only write an else statement at the end of a conditional statement.
x is any valid expression that can evaluate to 0 in some cases. Only the return value of x is considered; it can be a Boolean expression or any other PTC Mathcad expression. For example, a local assignment or a sequence of programming steps is allowed.
y is any valid expression.
Watch this video to learn more about conditional operators:
Additional Information
You can type the name of a conditional operator (with no spaces) and then press Ctrl+J to convert the name to a conditional operator with all its placeholders.
Conditional statements allow PTC Mathcad to execute or skip certain calculations. Use a conditional statement whenever you want to direct program execution along a particular branch.
Each conditional evaluation is considered on its own. When PTC Mathcad encounters several sequential if statements at the same level, it evaluates each if statement in turn, regardless of the results of the previous statement. If you want to evaluate an expression based on whether a particular if statement evaluates as true or false, use the else, elseif, or alsoif operator.
When PTC Mathcad processes a conditional statement, it proceeds to the next line regardless of whether y is evaluated or not.
Was this helpful?