concept break statement in category java

appears as: break statement, break statements
Java SE 11 Programmer I Certification Guide MEAP V03

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide MEAP V03.

In this section, you’ll learn how to use the switch statement and see how it compares to nested if-else constructs. You’ll learn the right ingredients for defining values that are passed to the switch labels and the correct use of the break statement in these labels.

6.3.5   Use of break statements within a switch statement

In the previous examples, note the use of break to exit the switch construct once a matching case is found. In the absence of the break statement, control will fall through the remaining code and execute the code corresponding to all the remaining cases that follow that matching case.

Consider the examples shown in figure 6.11—one with a break statement and the other without a break statement. Examine the flow of code (depicted using arrows) in this figure when the value of the variable score is equal to 50.

Figure 6.11 Differences in code flow for a switch statement with and without break statements
OCA Java SE 8 Programmer I Certification Guide

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.

When a String object is passed as an argument to a switch construct, it doesn’t compare the object references; it compares the object values using the equals method. In the code snippet shown in the question, a match is found for the String literal value SUN, so the code prints Weekend!, executes the break statement, and exits the block.

In this section, you’ll learn how to use the switch statement and see how it compares to nested if-else constructs. You’ll learn the right ingredients for defining values that are passed to the switch labels and the correct use of the break statement in these labels.

5.2.5. Use of break statements within a switch statement

In the previous examples, note the use of break to exit the switch construct once a matching case is found. In the absence of the break statement, control will fall through the remaining code and execute the code corresponding to all the remaining cases that follow that matching case.

Consider the examples shown in figure 5.10—one with a break statement and the other without a break statement. Examine the flow of code (depicted using arrows) in this figure when the value of the variable score is equal to 50.

Figure 5.10. Differences in code flow for a switch statement with and without break statements
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest