Control flow

for walks the values

Two loops, and no surprises in their shape. while (cond) { ... } runs as long as a Bool holds, and for x in xs { ... } walks a collection. The for takes no parentheses — there’s no test to wrap, just a name and the thing you’re iterating.

One reflex to unlearn if you’re coming from JavaScript: for x in xs hands you each value, not an index. It reads like JS’s for...in (which gives you keys), but it behaves like for...of. No xs[i] dance — you get the item itself.

s is 10, then 20, then 30 — the values — so total lands on 60. Looping over indices instead would have summed to 3.