We break down the
when
(
value
) construct as a more readable alternative to 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 matching order, and a practical example of a console menu with safe input parsing via
toIntOrNull(), early exit using
return, and retrying input with
continue.