Skip to content
Make room for learningYour learning studio
An if needs a boolean4 min

Loading your session…

A small idea, worth understanding

An if needs a boolean

Use boolean comparisons in Rust branches.

Rust requires the condition of an if to be a bool. It does not treat a number as automatically true or false.

An if expression can return a value when both branches have compatible types.

Two activities. No typing needed. You can always retry, or read an explanation and continue.

Read the full lesson first