By Tony Bevis on Tuesday, 10 October 2023
Category: Java

Java programming course: 5.7 The if else block

In the previous lesson you learnt about compound operators.

The if else block

You can use the else statement when you need to specify what should happen if the condition is not met. For example, you could modify the weatherCheck() method from the previous lesson:

You can also use else to test several alternate conditions:

The following snippet shows an example of using the above method:

In the next lesson you will learn about the ternary operator.

Next lesson: 5.8 The ternary operator

Related Posts

Leave Comments