if Constract Variation #2

  • In the previous example, you'd probably want to display a message for people older than 21.
  • You can add a second if statement (i.e. if (age >= 21)) after the first one and you got what you want.
  • But, C/C++ have a more efficient construct:
  •    if (condition)
       {
          // Commands group 1
       } else
       {
          // Commands group 2
       }
  • Intuitively, this means: If the condition satisfied, the commands group 1 get executed, otherwise, the commands group 2 get executed.
  • Let's modify our example.

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001