what is the index variable

1 回表示 (過去 30 日間)
Paola Alexsandra Barrera-Zevallos
Paola Alexsandra Barrera-Zevallos 2018 年 3 月 1 日
編集済み: Stephen23 2018 年 3 月 1 日
Consider the execution of the following MATLAB code:
a = 11;
b = 4;
z = 5:5:25;
for k = a:-1:b
if k > 5
z = z - 5; %
elseif k == 3
z = z - 10; %
else
z = z - 4; %
end
end %
% Which is the loop index variable?

回答 (1 件)

Stephen23
Stephen23 2018 年 3 月 1 日
編集済み: Stephen23 2018 年 3 月 1 日
k is the loop index variable in the code that you showed. The loop index variable is always defined after for:
for ??? = ...
^ this is where the loop index available is specified.
This is also shown in the MATLAB documentation:

カテゴリ

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