Conditional statement

Updated: 09/15/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. It is sometimes referred to as an If-Then statement, because IF a condition is met, THEN an action is performed.

For example, consider the following textual example of a conditional statement.

IF a value is less than 10, THEN display the words "Value is less than 10" on the screen

The above example is how a conditional statement might be interpreted by the human brain. Using a computer programming language, the above conditional statement could be written like the example statements below.

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, it will print "The value equals 10" to the screen. Otherwise, it will 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 one of three messages to the screen, depending if the value is greater than 10, less than 10, or equal to 10.

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