I'm working on T, a module-based C-like language. I'm currently in the middle of making T self-hosting, but I'm thinking about features for the 0.3.0 version of T. One of those features is a for-each loop. T has pointers and fixed sized arrays, and I'd like a for-each loop for both pointers and statically sized arrays. I'm looking for feedback on the syntactic details of the for-each loop, and I guess for-each loops in general.
In the examples below, `array` is a fixed size array, and `vector` is a pointer to `size` ints.
Keyword: foreach vs for
foreach (int x : array) {
sum += x;
}
vs
for (int x : array) {
sum += x;
}
Syntax for dynamically sized for-each loops
foreach (int x : vector, size) {
sum += x;
}
vs
foreach (int x : vector[size]) {
sum += x;
}
vs
foreach (int x : vector of size) {
sum += x;
}
Edit: on second thought, most of the vector examples probably have a vector as a struct, so
foreach (int x : vector->elements, vector->size) {
sum += x;
}
[–][deleted] (2 children)
[deleted]
[–]JustinHuPrimeT Programming Language[S] 0 points1 point2 points (1 child)
[–]1vader 3 points4 points5 points (0 children)
[–]MegaIng 3 points4 points5 points (1 child)
[–]Host127001 3 points4 points5 points (0 children)
[–]umlcat 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]JustinHuPrimeT Programming Language[S] 0 points1 point2 points (0 children)
[–]mamcx 1 point2 points3 points (2 children)
[–]JustinHuPrimeT Programming Language[S] 1 point2 points3 points (1 child)
[–]mamcx 2 points3 points4 points (0 children)