Else statements

An else statement indicates an alternate group of instructions to perform if no preceding if or else if condition was true.

Loading TypeScript...

An else statement must always have a corresponding if statement.

Notice how the program below works correctly for all possible values except for 7. The else statement is only paired with the single if statement that precedes it.

Was this page helpful?