Improved for loops

This commit is contained in:
2026-05-22 02:52:22 +02:00
parent 960cc40886
commit b7cfa9fbe6
5 changed files with 37 additions and 12 deletions
+15 -4
View File
@@ -94,6 +94,7 @@ impl GenRust for Statement {
Statement::While(StatementBranch { condition, body }) => {
cg.add("while ");
condition.gen_rust(ctx, cg);
cg.add(" ");
cg.ensure_brackets(ctx, body);
}
@@ -103,17 +104,25 @@ impl GenRust for Statement {
update,
body,
} => {
cg.add_indentedln("{");
cg.addln("{");
cg.indent += 1;
ctx.expr_ensure_semicolon = true;
cg.add_indented("");
init.gen_rust(ctx, cg);
cg.add("while ");
cg.addln("");
cg.add_indented("while ");
ctx.expr_ensure_semicolon = false;
condition.gen_rust(ctx, cg);
cg.add("{");
cg.add(" ");
cg.add("{");
cg.indent += 1;
ctx.expr_ensure_semicolon = true;
@@ -122,11 +131,13 @@ impl GenRust for Statement {
update.gen_rust(ctx, cg);
cg.addln("");
cg.indent -= 1;
cg.add_indentedln("}");
cg.indent -= 1;
cg.add_indentedln("}");
cg.add_indented("}");
}
Statement::For {