Introducing the if()… else… complex statement
if()… else… is a complex statement that can have two forms – a simple form where the if()… part is present, and a complete form where both the if()… and else… parts are present.
In the if()… else… complex statement, either the true path or the false path will be executed. The path that is not taken will be ignored. In the simplest if()… statement where there is no false path, the true path is executed only if the conditional expression is true.
The statement has two syntactical forms, as follows:
- The simplest form (no
falsepath), as illustrated in the following code snippet:if( expression ) Â Â statement1 statement3Â Â Â Â Â Â Â Â Â /* next statement to be executed */
- The complete form (both the
truepath and thefalsepath), as illustrated in the following code snippet:if( expression )Â Â ...