Better syntax for collecting into array including both end points

The following code shows two ways of collecting data into an array.
MyArray0 may not include YrEnd depending on YrStep.
MyArray1 always includes YrEnd regardless of YrStep.

Question, is there a better or more elegant way to code MyArray1…Archie

# sample data to drive MyArray0 and MyArray1
YrBeg = 1751
YrStep = 10
YrEnd = 1776
MyArray0 = collect(YrBeg:YrStep:YrEnd) # YrEnd may not be in MyArray0
MyArray1 = push!(collect(YrBeg:YrStep:YrEnd-1), YrEnd) # YrEnd always in MyArray1
@show(MyArray0, MyArray1)
# is there a simpler or more elegant way to code MyArray1?

You can write vcat(YrBeg:YrStep:YrEnd-1, YrEnd), perhaps?

1 Like

Yes. That is more concise.

range(a, b, length=n)

1 Like

That works if reals are allowed, however I desire all the values to be integers. Thx…Archie

OK I see, you didn’t actually say that as far as I can see.

Here’s an alternative syntax for the vcat suggestion:

julia> n = 5
5

julia> [1:2:n-1; n]
3-element Array{Int64,1}:
 1
 3
 5

Good bust! Shortest yet.