#include "MusimatTutorial.h"Go to the source code of this file.
Functions | |
| MusimatTutorialSection (B0116) | |
| MusimatTutorialSection | ( | B0116 | ) |
Definition at line 2 of file B0116.cpp.
References y.
{
Print("*** B.1.16 Conditional Statements ***");
/*****************************************************************************
B.1.16 Conditional Statements
A mathematical notation for determining the sign of a number is
| x < 0, a
y = |
| x >= 0, b
which sets y to a if x is negative; otherwise it sets y to b. Such relational expressions are called
predicates. Musimat accomplishes the same thing like this:
*****************************************************************************/
Real a = 1;
Real b = 2;
Real y = 5;
If (y < 0)
y = a;
Else
y = b;
/*****************************************************************************
In this example, y receives the value of a if y is less than 0; otherwise y receives the value of b.
The Else part of this construction is optional. So for example,
*****************************************************************************/
If (a < b)
Print(a);
/*****************************************************************************
prints a only if it is less than b. If and Else can be combined to allow chains of predicates:
*****************************************************************************/
Real r = -1.0;
If (a < 0) // is x negative?
y = a;
Else If (a == 0) // it's not negative, but is it zero?
y = b;
Else // neither negative nor zero, x must be positive
y = r;
}
1.7.2