Else Statement
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
Else
Do Another Thing
End If
Or If X = 1 Then
Do Statement 1
Else If X = 2 Then
Do Statement 2
Else
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.
Survey: Why Is There Still a Gender Gap in Tech?
Do you work in the tech industry? Help us learn more about why the gender gap still exists in tech by taking this quick survey! Survey respondents will also be entered to win a $100 Amazon Gift Card!
Related Reading
- Computer Programming for the People?
- The Pioneers of Computer Programming
- INFOGRAPHIC: The History of Programming Languages
- Data Breach Notification: The Legal and Regulatory Environment
- Artificial Intelligence in Cybersecurity
- The Differences Between the Top 3 Cryptocurrencies