Up to this point we have seen that program’s statements are executed from top to bottom, in the order that they appear inside the source code. However, in real programming, certain statements should be executed only if specific conditions are met. This chapter will teach you how to use if and switch selection statements to control the flow of your program and make it select a particular execution path from a set of alternatives. It also introduces the conditional operator (?:), which can be used to form conditional expressions.
The if statement controls program flow based on whether a condition evaluates to true or false. The simplest form of if statement is
… /* block of statements. */ ...