for-next loop parameter gets printed out
1 view (last 30 days)
Curious behavior. I have a matlab code with lots of for-next loops. One in particular that starts with
for I = J:LL
for some reason resulted in the LL value being printed out unexpectedly. None of my other for-next loops
did this. When I changed the statement to read
for I = J:LL;
i.e., I added a semicolorn to the end, LL was NOT printed out. This is worrisome because I'm not sure something
else has gone wrong. How does one track down what causes this behavior?
dpb on 21 Aug 2022
Edited: dpb on 21 Aug 2022
You've got a malformed for expression, the comma serves to make a second line of code on the same source line; the value of ll is echo'ed to the screen as asked for by this syntax.
for l = 1,ll
is syntactically the same as
for l = 1
You undoubtedly intended to write
So, indeed, something else did go wrong besides; the loop only executed once instead of ll times since were no colon operators to set either step nor upper bound.
And, in this case the typo is also not a syntax error nor can the parser presume you didn't have some reason for only executing the loop once.