条件文の使用
条件文を使用すると、各種条件が真または偽のいずれであるかに応じて処理を実行できます。括弧 ( と ) を使用してグループ化することにより、さらに複雑な条件を指定できます。
条件 |
説明 |
---|---|
が次に等しい | 式 = = 式 |
が等しくない | 式 != 式 |
次の値より大きい | 式 > 式 |
次の値以上 | 式 >= 式 |
次の値より小さい | 式 < 式 |
次の値以下 | 式 <= 式 |
条件が偽 | ! 条件 |
And | 条件 && 条件 |
Or | 条件 || 条件 |
If 文
if(condition)
{
actions to take if condition is true
}
中括弧は、"if" の後で複数の文を実行する場合のみ必要です。
If-Else If 文
if(condition)
{
actions to take if condition is true
}
else if(condition)
{
actions to take if condition is true
}
else if...
if(SideLength != NaN)
{
AreaOfPolygon=
((SideLength^2)*NumberOfSides)/
(4*Tan(pi/NumberOfSides));
}
else if(Radius != NaN)
{
AreaOfPolygon=
(Radius^2)*NumberOfSides*Sin((2*pi)/NumberOfSides)/2;
}
else if 文は複数指定できます。中括弧は、"if-else- if-else" の後で複数の文を実行する場合にのみ必要です。
Else-If 文
if(condition)
{
actions to take if condition is true
}
else if(condition)
{
actions to take if condition is true
}
else if...
else
{
actions to take if no conditions are met
}