We break down the
when
(
value
) construct as a more readable replacement for a long
if/
else if chain: the basic branch syntax with the
-> operator, the role of the
else branch, blocks
{...
} inside branches, top-to-bottom checking order, and also a practical example of a console menu with safe input parsing via
toIntOrNull(), early exit with
return, and repeated input via
continue.