フィルターのクリア

After the if statement is ran why is the answer 10?

1 回表示 (過去 30 日間)
Allison Sims
Allison Sims 2022 年 7 月 30 日
コメント済み: Voss 2022 年 7 月 31 日
A=1;
B=2;
C=10;
if A<0
C=5;
if B==2
C=3; %I thought the answer would be 3 why is it 10?
end
end
disp(C)
10

採用された回答

Voss
Voss 2022 年 7 月 30 日
A=1;
B=2;
C=10;
if A<0 % false (1 is not less than 0)
% ... nothing in here executes
end
disp(C) % C remains 10
10
  2 件のコメント
Allison Sims
Allison Sims 2022 年 7 月 30 日
Ohh okay that makes sense thank you very much
Voss
Voss 2022 年 7 月 31 日
You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2022 年 7 月 30 日
A=1;
:
if A<0
A is not negative, so the body of the if-test never runs.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by