changes in iterators #1670
Replies: 3 comments 1 reply
-
C-style for-loops are complex to read and write, especially in cases where the index isn't just an integer. That's why Carbon (and Swift, Go, Kotlin, Rust...) use let i: u8 = 0;
while (i < a.len) {
...
i++;
} But also, this type of loop should be a lot less common in Carbon than in C++, due to things like slices. |
Beta Was this translation helpful? Give feedback.
-
Please feel free to write up a formal proposal and send it for comment. :) |
Beta Was this translation helpful? Give feedback.
-
Please also see #471, which proposed some concrete details of loops, but was deferred due to the general lack of an overall loop design. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
itr (e <- a) {}
instead
for (e in a)
for
would be used only as c-likefor
in
would be used to check if an element isin
a collection, for instance:Beta Was this translation helpful? Give feedback.
All reactions