1 / 7

The if Statement

The if Statement. The basic if statement allows your program to execute a single statement, or a block of statements enclosed between braces, if a given condition is true. This is illustrated in the Figure 1. no. if (condition) statement; next statement; or if (condition) { statement;

Télécharger la présentation

The if Statement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The if Statement • The basic if statement allows your program to execute a single statement, or a block of statements enclosed between braces, if a given condition is true. • This is illustrated in the Figure 1. tMyn

  2. no if (condition) statement; next statement; or if (condition) { statement; statement; … } next statement; condition is true? yes Statement or Block of Statements Next Statement Figure 1. The statement or block of statements that follows the if is only executed If condition is true. tMyn

  3. A simple example of an if statement to test the value of a variable called letter: if($letter==‘A’) echo “The first capital! <br>"; echo “This is not part of if structure!! <br>"; The condition to be tested appears ALWAYS in parentheses!! tMyn

  4. tMyn

  5. tMyn

  6. The statement that is to be executed when the condition in an if statement is true can itself be an if statement. • This arrangement is called a nested if. • The condition of the inner if is only tested if the condition for the outer if is true. • An if that is nested inside another can also contain a nested if. tMyn

  7. If this is NOT true, we will never visit here!! if($letter>=‘A’) { if($letter<=‘Z’) { echo “You entered an upper case letter. <br>"; … } } tMyn

More Related