Tutorials > Programming > Task 2–1: Writing If Statements
Task 2–1: Writing If Statements
Write a function reverse that modifies the value of its argument from “BLACK” to “WHITE” and vice versa.
1. Create a new function reverse that accepts a variable var as its input argument.
2. To add an if statement, on the Math tab, in the Operators and Symbols group, click Programming. The programming operators list opens. Click if.
You can type the name of a programming operators, such as "if”, and then press Ctrl+J to convert the name to a programming operator with all its placeholders.
3. Condition that if the value of var is “BLACK”, the function returns the value “WHITE” as shown below. To add the Boolean equal operator for comparison, on the Math tab, in the Operators and Symbols group, click Operators. The operators list opens. Click = Equal To.
4. To add another if statement, position the cursor as shown below and press Enter.
If the cursor is positioned right after “WHITE” and you press Enter, PTC Mathcad adds a line inside the if block.
5. Specify the opposite case as shown below.
PTC Mathcad supports nested if statements.
6. Call reverse and change the value of a variable myvar as shown below.
Keep the file open and proceed to Task 2–2.
Was this helpful?