Unit and Nothing
The Unit type represents "execution completed but no meaningful return value". Its only value is (), and side-effect operations such as println, assignment expressions, and loop expressions are all of Unit type.
Nothing is a special type that contains no values and is a subtype of all types. The types of break, continue, return, and throw expressions are all Nothing—when program execution reaches these expressions, the code after them will not be executed.
These two types are mainly used for expressing type system and control flow semantics, helping the compiler with type inference and flow analysis. The code on the right demonstrates typical use cases for Unit and Nothing.
Nothing currently cannot be explicitly used in type annotations; it is primarily used by the compiler for type inference.Try running the code and observing the return value of println and the execution of code after break.