Exerpad
🔥 0
0 XP
Exercise 8 · Chapter: While LoopsOptional+50 XP

Powers of Two

Use a while loop to print all powers of 2 from 1 up to 256, one per line.

Expected output:

1
2
4
8
16
32
64
128
256

Hints:

  • Start with let mut n = 1;
  • Multiply n by 2 each time
  • Loop while n <= 256
  • Print n before multiplying!
rust
fn main() {
}
Output
Run your code to see the output here.