Else Statement

What Does Else Statement Mean?

In programming languages, an else statement is an alternative statement that is executed if the result of a previous test condition evaluates to false.


Techopedia Explains Else Statement

The syntax of the else statement is very similar between different high-level programming languages like PHP, Java, C/C++/C#, Object Pascal, etc. Even early programming languages such as Basic and Fortran have the ability to process an else statement as part of a general syntactical approach to linear programming.

The else statement is an optional statement that is normally used in an "if-else" or "if-else if-else" construction. The way the else statement works is that, if the condition associated with either the "if" or the "else if" control structure is false, program control automatically goes to the else statement, if present.

For example,

 If X is true Then
Do Something
Do Another Thing
End If


 If X = 1 Then
Do Statement 1
Else If X = 2 Then
Do Statement 2
Do Another Thing
End If

Note that, unlike the "if" and "else if" control structure, there is no test condition associated with the else statement.

In Object Pascal, the else statement may also be used in a "case" statement and it serves the same purpose as the "default statement" in the C family of languages such as C/C++, C# and Java.


Related Terms

Latest Computer Science Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…