# Enumeration with shifted indices

**URL:** <https://discourse.julialang.org/t/enumeration-with-shifted-indices/11361>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 2, 2018, 8:02am UTC](https://discourse.julialang.org/t/enumeration-with-shifted-indices/11361 "2018-06-02T08:02:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leiteiro](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@leiteiro](https://discourse.julialang.org/u/leiteiro)\
**Post date:** [June 2, 2018, 8:02am UTC](https://discourse.julialang.org/t/enumeration-with-shifted-indices/11361/1 "2018-06-02T08:02:45Z")

</div>

```
enumerate(iter)

```

is an iterator that yields (i, x) where i is a counter  
starting at 1, and x is the i-th value from the given iterator.

How to define

```
enumerate(iter, start=0)

```

an iterator that yields (i+start, x) where i is a counter  
starting at 1, and x is the i-th value from the given iterator?

* * *

More generally, there is Base.Iterators.countfrom(start=1, step=1)  
which is an iterator starting at start and incrementing by step.

How to define

```
enumerate(iter, start=0, step=1)

```

which is an iterator that yields (i\*step+start, x) where i  
is a counter starting at 1, and x is the i-th value from the  
given iterator?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 2, 2018, 8:22am UTC](https://discourse.julialang.org/t/enumeration-with-shifted-indices/11361/2 "2018-06-02T08:22:00Z")

</div>

Here is one way:

```julia
julia> iter = ("A", "B", "C")
("A", "B", "C")

julia> for (i, a) in zip(Iterators.countfrom(0), iter)
           println("i = $i, a = $a")
       end
i = 0, a = A
i = 1, a = B
i = 2, a = C

julia> for (i, a) in zip(Iterators.countfrom(0, 2), iter)
           println("i = $i, a = $a")
       end
i = 0, a = A
i = 2, a = B
i = 4, a = C

```
