Skip to content

Conversation

@p1k0chu
Copy link
Contributor

@p1k0chu p1k0chu commented Jan 19, 2026

fix for loops with indexes and pointers, commit messages have detailed info:

[zig] fix arrays iterations with indexes

the syntax `for (array) | value, i | {}` gives compile time error
for an extra capture group

you need to add another iterable like 0.. for this to work

also added a simple for loop over multiple iterables
to demostrate this
---
[zig] fix array iteration with pointers

this syntax iterates over an array of pointers
```
for (items) |*value| {}
```
and crashes if you iterate over a normal array like [_]i32

to capture a pointer to an array item itself, this is correct:
```
var items = [_]i32{...};
for (&items) |*value| {}
```
  • I solemnly swear that this is all original content of which I am the original author
  • Pull request title is prepended with [language/lang-code] (example [python/fr] for Python in French or [java] for multiple Java translations)
  • Pull request touches only one file (or a set of logically related files with similar changes made)
  • Content changes are aimed at intermediate to experienced programmers (this is a poor format for explaining fundamental programming concepts)
  • If you've changed any part of the YAML Frontmatter, make sure it is formatted according to CONTRIBUTING.md. i didn't

@p1k0chu p1k0chu marked this pull request as ready for review January 19, 2026 13:49
the syntax `for (array) | value, i | {}` gives compile time error
for an extra capture group

you need to add another iterable like 0.. for this to work

also added a simple for loop over multiple iterables
to demostrate this
this syntax iterates over an array of pointers
```
for (items) |*value| {}
```
and crashes if you iterate over a normal array like [_]i32

to capture a pointer to an array item itself, this is correct:
```
var items = [_]i32{...};
for (&items) |*value| {}
```
manually filtered all "typos" from hunspell
@vendethiel vendethiel merged commit 3520e49 into adambard:master Jan 26, 2026
@vendethiel
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants