< Previous | Contents | Next >
Okay, it’s time to put the concepts of true and false to work. You can use an if statement to test an expression for truth and execute some code based on it. Here’s a simple form of the if statement:
if (expression)
statement;
If expression is true, then statement is executed. Otherwise, statement is skipped and the program branches to the statement after the if suite.
Hi n t
Whenever you see a generic statement like in the preceding code example, you can replace it with a single statement or a block of statements because a block is treated as a single unit.