Guarded Equations
Guarded equations provide an alternative to if-else statements and are especially useful when we need multiple ifs in our code. Like MultiWayIfs
, they represent a sequence of expressions that evaluate to either True
or False
(conditions) which are individually called guards and are used to decide the flow of the program. The syntax is very similar to the MultiWayIf
syntax and allows us to get rid of the if
keyword altogether:
Note that in the above implementation of guarded equations, we have moved the equation sign in the line trackScore time avgTime
, and we have replaced the ifs arrow (->)
with it.
Last updated