for arr: (it) {}

This commit is contained in:
agra
2026-02-16 00:55:03 +02:00
parent 3e1e764753
commit fb60818424
7 changed files with 88 additions and 56 deletions

View File

@@ -2,14 +2,14 @@
sum :: (args: ..s32) -> s32 {
result := 0;
for args {
for args: (it) {
result = result + it;
}
result;
}
print_all :: (args: ..s32) {
for args {
for args: (it) {
write(int_to_string(it));
write(" ");
}
@@ -26,7 +26,7 @@ main :: () -> s32 {
write(int_to_string(sum(..arr)));
write("\n");
for arr {
for arr: (it) {
write(int_to_string(it));
write(" ");
}

View File

@@ -7,7 +7,7 @@ Point :: struct {
// Print all arguments — accepts any type, dispatches via type-switch
print_any :: (args: ..Any) {
for args {
for args: (it) {
type := type_of(it);
if type == {
case int: write(int_to_string(cast(s32) it));

View File

@@ -53,7 +53,7 @@ pair_add :: (a: $T, b: $U) -> s64 {
typed_sum :: (args: ..s32) -> s32 {
result := 0;
for args { result = result + it; }
for args: (it) { result = result + it; }
result;
}
@@ -635,7 +635,7 @@ END;
// For loop basic
farr : [4]s32 = .[10, 20, 30, 40];
write("for:");
for farr {
for farr: (it) {
write(" ");
write(int_to_string(it));
}
@@ -643,29 +643,29 @@ END;
// For with print
write("for-print:");
for farr {
for farr: (it) {
print(" {}", it);
}
write("\n");
// For with it_index
// For with index
write("for-idx:");
for farr {
for farr: (_, ix) {
write(" ");
write(int_to_string(it_index));
write(int_to_string(ix));
}
write("\n");
// For with print two args
write("for-2arg:");
for farr {
print(" {}@{}", it, it_index);
for farr: (it, ix) {
print(" {}@{}", it, ix);
}
write("\n");
// For with break
write("for-break:");
for farr {
for farr: (it) {
if it == 30 { break; }
print(" {}", it);
}
@@ -673,7 +673,7 @@ END;
// For with continue
write("for-continue:");
for farr {
for farr: (it) {
if it == 20 { continue; }
print(" {}", it);
}
@@ -682,15 +682,15 @@ END;
// For on slice
fsl : []s32 = .[10, 20, 30];
write("for-slice:");
for fsl {
for fsl: (it) {
print(" {}", it);
}
write("\n");
// For on slice with it_index
// For on slice with index
write("for-slice-idx:");
for fsl {
print(" {}:{}", it_index, it);
for fsl: (it, ix) {
print(" {}:{}", ix, it);
}
write("\n");
@@ -698,19 +698,18 @@ END;
nf_a : [2]s32 = .[0, 1];
nf_b : [2]s32 = .[0, 1];
write("for-nested:");
for nf_a {
oa := it;
for nf_b {
print(" ({},{})", oa, it);
for nf_a: (oa) {
for nf_b: (ob) {
print(" ({},{})", oa, ob);
}
}
write("\n");
// For with break preserving it_index
// For with break preserving index
fbi : [5]s32 = .[10, 20, 30, 40, 50];
fbi_idx := 0;
for fbi {
if it == 30 { fbi_idx = it_index; break; }
for fbi: (it, ix) {
if it == 30 { fbi_idx = ix; break; }
}
print("for-break-idx: {}\n", fbi_idx);