Conditional statement

Updated: 04/26/2017 by Computer Hope

condition expressionAlternatively referred to as a conditional expression and conditional processing, a conditional statement is a set of rules performed if a certain condition is met. 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 prints "Value is less than 10" to the screen.

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" to the screen.

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.

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