From 0a80344c07e39ed9c7c5bca9e5f17e5b8612c4bc Mon Sep 17 00:00:00 2001 From: Yui Date: Sat, 29 Nov 2025 23:08:50 +0300 Subject: [PATCH] Add C-style for loops --- docs/bext.md | 13 +++++++++++ src/b.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ src/lexer.rs | 3 +++ tests.json | 56 ++++++++++++++++++++++++++++++++++++++++++++++ tests/for_loop.b | 27 ++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 tests/for_loop.b diff --git a/docs/bext.md b/docs/bext.md index b2993251..75e77308 100644 --- a/docs/bext.md +++ b/docs/bext.md @@ -56,6 +56,19 @@ Some targets like `gas-aarch64-darwin` have a different calling convention for v this is needed to make the compiler use the correct calling convention. \ the syntax is `__variadic__(function_name, number_of_fixed_args);` +## C-style for loops +```c +main() { + for (auto i = 2; i < 5; i++) { + printf("%lld^2 = %lld\n", i, i*i); + } + + for(;;) printf("infinite loop\n"); +} +``` + +Very useful for iterating over a range of numbers. +