add for loops

This commit is contained in:
Sil Klaasboer
2025-12-18 12:58:26 +01:00
parent de13a80f99
commit 7b9aad5fc8

View File

@@ -61,5 +61,29 @@ fn main() {
loop_cycles += 1 loop_cycles += 1
}; };
println!("it took {} cycles to resolve the expression",result) println!("it took {} cycles to resolve the expression",result);
//while
loop_cycles = 1;
while 5 > loop_cycles {
if loop_cycles == 2
{
loop_cycles +=1;
continue;
}
println!("while loop {}",loop_cycles);
loop_cycles += 1;
}
//for loops
//1..5 is 1 up to 5 not including 5
for x in 1..5
{
println!("for loop: {}",x);
}
//1..=5 is 1 up to and including 5
for x in 1..=5
{
println!("for loop including: {}",x);
}
} }