JS Built-ins
ControlFlowbeginner

Control Flow β€” while loop

while loop: condition-based iteration

A while loop keeps running as long as the condition is true. Use when you don't know the iteration count in advance.

Challenge: Write countdown(n) that returns an array [n, n-1, ..., 1] using a while loop.

πŸ’‘ Hints (1)
  • β€’ Push n first, then decrement; stop when n reaches 0