Conditional statement

Alternatively referred to as a conditional expression and conditional processing, a conditional statement is a statement performed if true or false. Below are some examples of conditional statements in programming.

if ($myval < 10) { print "Value is less than 10"; }

In this example, if the variable $myval is less than 10, the software program will print Value is less than 10.

if ($myval == 10) { print "The value equals 10"; }
else { print "Value is not equal to 10"; }

In this example, if the variable is exactly equal to 10 then print The value equals 10, otherwise print Myval is not equal to 10.

if ($myval > 10) { print "Value is greater than 10"; }
elsif ($myval < 10) { print "Value is less than 10"; }
else { print "The value equals 10"; }

Finally, this last example will print if it is greater than 10, less than 10 or equal to 10.

Related pages

Also see: Boolean, Else, Else if, Expression, If else, If statement, Operator, Programming terms, Statement