Matlab-if-end-statement-matlab
提供:Dev Guides
MATLAB-if … 終了ステートメント
*if ... end* ステートメントは、 *if* ステートメントと、1つ以上のステートメントが後に続くブール式で構成されます。 *end* ステートメントで区切られています。
構文
MATLABのifステートメントの構文は-
if <expression>
% statement(s) will execute if the boolean expression is true
<statements>
end
式の評価がtrueの場合、ifステートメント内のコードブロックが実行されます。 式の評価がfalseの場合、endステートメントの後の最初のコードセットが実行されます。
流れ図
例
スクリプトファイルを作成し、次のコードを入力します-
a = 10;
% check the condition using if statement
if a < 20
% if condition is true then print the following
fprintf('a is less than 20\n' );
end
fprintf('value of a is : %d\n', a);
あなたがファイルを実行すると、次の結果が表示されます-
a is less than 20
value of a is : 10