Cloudbook: C

  1. Home
  2. Control
  3. If/Else
  4. § 2 exercise →
If/Else

The If Statement runs a block of code only in the case where the controlling logical expression gives true. So there are two things that make up an if statement, three if you count the word if: there is a logical expression, and there is a block of code. The syntax is precise in the layout of these two elements and the keyword if.

There ar many variants of the if statement. We had seen the use of the and logical operator to get the effect of an if statement. Recall that the evaluation of a logical expression can cause conditional evaluation. A logical expression such as

        $a || print "hi"
will try to evalute the right hand expression only if $a is false. So in effect, this expression can be read as: print "hi" if $a is false.