Conditionals
Understand how to write conditional statements in C to control program flow. Learn to use if, else, and else if constructs to execute code based on conditions, and explore the shorthand conditional operator for simpler expressions. This lesson helps you make decisions within your C programs effectively.
We'll cover the following...
We'll cover the following...
One of the most important constructs in programming is the ability to execute (or not execute) pieces of code, or execute different pieces of code, depending on the outcome of some decision or question about data. The if-else construct lets us execute code selectively in C based on conditions defined by us.
The if statement
The basic if statement looks like this:
The program ...