#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.
00002 { 00003 Print("*** B.1.16 Conditional Statements ***"); 00004 /***************************************************************************** 00005 00006 B.1.16 Conditional Statements 00007 00008 A mathematical notation for determining the sign of a number is 00009 00010 | x < 0, a 00011 y = | 00012 | x >= 0, b 00013 00014 00015 which sets y to a if x is negative; otherwise it sets y to b. Such relational expressions are called 00016 predicates. Musimat accomplishes the same thing like this: 00017 *****************************************************************************/ 00018 00019 Real a = 1; 00020 Real b = 2; 00021 Real y = 5; 00022 00023 If (y < 0) 00024 y = a; 00025 Else 00026 y = b; 00027 00028 /***************************************************************************** 00029 In this example, y receives the value of a if y is less than 0; otherwise y receives the value of b. 00030 The Else part of this construction is optional. So for example, 00031 *****************************************************************************/ 00032 00033 If (a < b) 00034 Print(a); 00035 00036 /***************************************************************************** 00037 prints a only if it is less than b. If and Else can be combined to allow chains of predicates: 00038 *****************************************************************************/ 00039 Real r = -1.0; 00040 00041 If (a < 0) // is x negative? 00042 y = a; 00043 Else If (a == 0) // it’s not negative, but is it zero? 00044 y = b; 00045 Else // neither negative nor zero, x must be positive 00046 y = r; 00047 00048 }}
1.4.7