Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
else |
Component of conditional statements | L | Keyword | C89 | C90 | C95 | C99 | C11 | |||
if |
Component of conditional statements | L | Keyword | C89 | C90 | C95 | C99 | C11 |
A conditional statement is a construct that,
when executed, chooses from a group of enclosed statements
according to the value of an expression, and executes them. The
if
statement has the form:
- selection-statement
if ( expression ) statement
if ( expression ) statement else statement
The expression is interpreted as a condition. When executed, the
condition is evaluated. If it is non-zero (true), the first
enclosed statement is executed; otherwise, the second is
executed. The
else
branch can be omitted, if nothing needs to
be done when the condition is false.
if
statements can be chained together if more
than two branches or conditions are required:
if (condition) statement else if (condition) statement else if (condition) statement else statement
An alternative to this might be to use switch
.
If you need more than one statement in a branch, you can make it a block statement:
if (condition) { . . . } else { . . . }