diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 18:25:56 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 18:25:56 +0100 |
| commit | a88d11b3d0e1169294a710baffc3b9598a2d635c (patch) | |
| tree | 8ef425bdc7e16ae213670423073e17c175111319 /examples/foreach.c | |
| parent | d036b496a24dadcb8124807010aacaa17242aaa8 (diff) | |
| download | nonstd-a88d11b3d0e1169294a710baffc3b9598a2d635c.tar.gz | |
Fix formatting in examples
Diffstat (limited to 'examples/foreach.c')
| -rw-r--r-- | examples/foreach.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/examples/foreach.c b/examples/foreach.c index 628c993..91407ee 100644 --- a/examples/foreach.c +++ b/examples/foreach.c @@ -8,21 +8,27 @@ int main(void) { int numbers[] = {10, 20, 30, 40, 50}; int num; // Declare the loop variable - static_foreach(int, num, numbers) { printf(" Number: %d\n", num); } + static_foreach(int, num, numbers) { + printf(" Number: %d\n", num); + } printf("\n"); // Example 2: Iterate over an array of floats float prices[] = {9.99f, 19.99f, 29.99f, 49.99f}; float price; // Declare the loop variable - static_foreach(float, price, prices) { printf(" Price: $%.2f\n", price); } + static_foreach(float, price, prices) { + printf(" Price: $%.2f\n", price); + } printf("\n"); // Example 3: Iterate over an array of strings const char *fruits[] = {"Apple", "Banana", "Cherry", "Date", "Elderberry"}; const char *fruit; // Declare the loop variable - static_foreach(const char *, fruit, fruits) { printf(" Fruit: %s\n", fruit); } + static_foreach(const char *, fruit, fruits) { + printf(" Fruit: %s\n", fruit); + } printf("\n"); // Example 4: Perform calculations with static_foreach @@ -30,7 +36,9 @@ int main(void) { int sum = 0; int val; // Declare the loop variable - static_foreach(int, val, values) { sum += val; } + static_foreach(int, val, values) { + sum += val; + } printf(" Sum of values: %d\n", sum); printf("\n"); @@ -43,7 +51,9 @@ int main(void) { Person people[] = {{"Alice", 25}, {"Bob", 30}, {"Charlie", 35}}; Person person; // Declare the loop variable - static_foreach(Person, person, people) { printf(" %s is %d years old\n", person.name, person.age); } + static_foreach(Person, person, people) { + printf(" %s is %d years old\n", person.name, person.age); + } printf("\n"); // Example 6: Modify array elements in place @@ -51,7 +61,9 @@ int main(void) { int n; // Declare the loop variable printf(" Before: "); - static_foreach(int, n, nums) { printf("%d ", n); } + static_foreach(int, n, nums) { + printf("%d ", n); + } printf("\n"); // Note: static_foreach creates a copy of each element by default @@ -61,7 +73,9 @@ int main(void) { } printf(" After doubling: "); - static_foreach(int, n, nums) { printf("%d ", n); } + static_foreach(int, n, nums) { + printf("%d ", n); + } printf("\n"); return 0; |
