Conditional expressions

Edit on Github instead

Conditional expressions allow our code to do different things based on a prior result.

It's like the logic we use every day: "it's cold, so I'll put on a coat"; "if you're running late, text your friend"; "if you're hungry, eat something; otherwise, go outside." In programming, those are known as if-else statements.

We also take repetitive actions. Some of those have an indeterminate end, e.g. "while I'd like to walk, move the left foot, then the right foot, then the left foot .. ", while others have a pre-defined stopping point: "read 2 chapters of the book" or "drive straight for 6 blocks and then turn left."

In programming, the former are mimiced with while loops and the latter with for loops.

Suggest changes

Related links

URL Topic Source