MATLAB Answers

Write a loop which will be increasing variable i by 5 at each iteration till i reaches 50. Initial value of i is 12.

1 view (last 30 days)
nty huy
nty huy on 7 Oct 2019
Edited: Walter Roberson on 7 Oct 2019
im having a bit trouble with loops if somone can help me with this answer and explain as well it would be nice

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 Oct 2019
Edited: Walter Roberson on 7 Oct 2019
for VARIABLENAME = FIRST_VALUE : INCREMENT : LAST_VALUE
something
end
is nearly equivalent to
VARIABLENAME = FIRST_VALUE;
while VARIABLE_NAME <= LAST_VALUE
something
VARIABLE_NAME = VARIABLE_NAME + INCREMENT;
end
(The differences between the two have to do with the value that VARIABLENAME is left at if FIRST_VALUE > LAST_VALUE when INCREMENT is positive, or FIRST_VALUE < LAST_VALUE when INCREMENT Is negative; and also have to do with the value that VARIABLENAME will be left with after the last iteration in two different situations.)

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags