How does if(0) work within a function?

14 ビュー (過去 30 日間)
Padma Sharma
Padma Sharma 2017 年 2 月 13 日
コメント済み: Padma Sharma 2017 年 2 月 13 日
I am looking at somebody else's code and found a function that looks like the following. As you can see below, I do not find any flag or if statement that precedes if(0) or any logical flag being used while calling the function. I would like to know how the right conditional is arrived at based on if(0) in this situation.
function [a,b] = updateParam(x,y,z)
% x,y,z are structures that are unpacked.
[e, f, g] = unpackX(x);
[h, i, j] = unpackY(y);
[k, l, m] = unpackZ(z);
for t = 1:k
if (0)
% perform these operations
else
% perform other operations
end
end

回答 (1 件)

David Goodmanson
David Goodmanson 2017 年 2 月 13 日
Hello Padma, if(0) always comes up false, so the operations after the 'else' statement will always be performed. It's a low-rent way to throw a switch so that the operations before the 'else' statement never happen.
  1 件のコメント
Padma Sharma
Padma Sharma 2017 年 2 月 13 日
Thank you very much David! This is very helpful.

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

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by