Ternary Operators and Conditionals

Background

Conditional statements execute code dependent on a condition. It is common for conditionals to alter program flow.

In the code snippet below, we assigned 0 or 1 depending on whether the original value is 0, 1, or -1. We wrote multiple lines of code for a single assignment, as shown below.

Get hands-on with 1200+ tech skills courses.