# Understanding iterate() documentation is tough

**URL:** <https://discourse.julialang.org/t/understanding-iterate-documentation-is-tough/134715>\
**Category:** General Usage\
**Tags:** documentation, iterators\
**Created:** [December 23, 2025, 11:06pm UTC](https://discourse.julialang.org/t/understanding-iterate-documentation-is-tough/134715 "2025-12-23T23:06:28Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [December 24, 2025, 12:32am UTC](https://discourse.julialang.org/t/understanding-iterate-documentation-is-tough/134715/4 "2025-12-24T00:32:35Z")

</div>

> [@raman\_kumar](#):
>
> Is Julia `for` loop behind the scene a `while` loop?

Behind the scenes, there’s no such thing as a for loop or while loop. It’s a bunch of gotos in intermediate code, LLVM `br`-anches, and ultimately native jumps. You can check with `Meta.@lower` or the `@code_###` reflection macros.

> [@raman\_kumar](#):
>
> is equivalent to

And no. First, your version omits the `iter` variable and adds extra stuff like `@show`, which are generally liberties you should avoid for documentation. Second, the for loop does not create a global variable `next` or the local variable `state`/`index`\*, so it’s obviously not the same as the while loop on the language level. “Equivalence” here means that a for loop uses the `iterate` function, provides the items via the iteration variable, and hides the state in a way that would be more visible in a while loop that accomplishes the same thing with extra variables. You can also see this in lowered code between the gotos.

> [@raman\_kumar](#):
>
> Why iterate(1:5) gives (1,1) that is `state=1` while iterate(“raman”) gives (‘r’, 2) that is `state=2`?

\*Together with this, your replacement of `state` in the documentation with `index` implies you think iteration states are the item’s indices. Indexing is implemented by a separate [interface](https://docs.julialang.org/en/v1/manual/interfaces/#Indexing), and there is no requirement for iterables to implement indexing, let alone use indices as iteration states.

> [@raman\_kumar](#):
>
> Similar question has been raised early also.

That question is actually asking about an entirely different aspect. Even if it weren’t, avoid linking topics unless your topic needs a quote or context because your topic’s links also create a mirroring link from those topics, which becomes progressively more confusing for other people looking up those topics in the future.

---

_[View the full topic](https://discourse.julialang.org/t/understanding-iterate-documentation-is-tough/134715)._
