This method is also a bit faster as you can check with @time. I guess that it's because there is only one "if" per loop as opposed to 2 "if" per loop in your design (Are we at the end of the array ? Is it a 0.0 ?).
François On Wednesday, May 21, 2014 12:09:02 AM UTC+2, [email protected] wrote: > > Hi, > > I would do a while as the loop is a conditional loop : > > function test(x::Vector{Float64}) > i = 1 > while i <= length(x) && x[i] != 0.0 > i += 1 > end > return i - 1 > end > > or I would use a return inside the for loop even though I prefer to avoid > a return in the middle of a function. Using a loop variable outside the > loop looks ugly to me. But it's a matter of taste. >
