(withdrawn but cannot figure out how to delete my own post)

question

#1

nevermind - problem was trailing comma on for statement


#2

Writing from my mobile so can’t check but you have a comma after the loop range in the first example.


#3

Thanks. I figured this out while you were answering. Is there some way I can delete my own topic? (embarrassing)


#4

No, you will forever live with the shame of having once made a typo in your code. :wink:


#5

This is actually a fairly common roadblock — one of the best reasons not to delete it is that you’re adding more search fodder for the next time someone else hits it:

(Note that the last two there are authored by core contributors)


#6

Thanks for making me feel a little better. I’m a long-time Matlab user, and many for-loop examples in that language use a trailing comma. I just did a little experiment in Matlab R2016b, and found that you can use a comma, semicolon, or just a space — even if the for-loop is all on one line, e.g.

>> for i=1:10  i, end
>> for i=1:10, i, end
>> for i=1:10; i, end

These are all syntactically okay, and execute the same way. Most of my lines of Matlab code end in semicolons to prevent the dreaded large-matrix scrolling-output problem, and I substitute commas when debugging to print intermediate values. Not sure why I got in the (bad) habit of the trailing comma on for-loops, if-blocks, etc. They might’ve been necessary in earlier versions . . .


#7

Interestingly, a trailing semicolon is valid in Julia:

julia> for i in 1:10  @show i end
julia> for i in 1:10; @show i end

Both lines do the same thing, whereas

julia> for i in 1:10, @show i end

produces a syntax error.