> C-style for loops can almost always be replaced with iterators in a more concise manner.
Not if you want to optimise for performance.A simple example: I search through a list of n items to find item m, iterators typically don't let you break out of the iteration.
Zig is the only contender I've seen where the for loop looks iterator-like, but also supports break/continue.
That'd be a pretty crappy iterator implementation, short-circuiting is basically what iterators are all about (how else would you handle infinite iterators?). For example, in Rust, it's simply Iterator::find(): https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...
for loops in Rust are basically just syntax sugar for a while loop taking an element of the iterator each iteration, you can use break/continue as normal.
I'm curious as to which language you worked with that didn't allow this.
edit: plus has a GC if you don't want to do manual memory management, already has a package manager, good at producing native/static binaries, can do automatic type inference, user defined types, cross compiling is super easy...
> without loops
This is a false dichotomy. You can use iterators to replace three-clause loops without changing the body:
for row in 0..rows {
for col in 0..cols {
arr[row][col]
}
}
This is far easier to read than three-clause loops which repeat redundant information repeatedly and redundantly.Is this (note the enclosing braces)
{
var thing = thinger();
while(cond(thing)) : (mutate(thing)){
// do whatever
}
}
really better than this? for(var thing = thinger(); cond(thing); mutate(thing)){
// do whatever
}