<< Chapter < Page Chapter >> Page >
Listing 7 . The program named switch2.java.
/*File switch2.java This is a Java application which uses a labeled break.Note that the program uses nested switch statements. See switch1.java for a comparison program which does notuse a labeled break. The program displays the following output:Match and break from here Beyond switch statements**********************************************************/ class switch2 { //define the controlling classpublic static void main(String[] args){ //main methodouterSwitch: switch(5){//labeled outer switch statement case 5: //execute the following switch statement//Note that the code for this case is not followed by // break. Therefore, except for the labeled break at// case 1, execution would fall through the case 6 and // the default as demonstrated in the program named// switch1. However, the use of the labeled break // causes control to break all the way out of the// labeled switch bypassing case 6 and the default. switch(1){ //inner switch statementcase 1: System.out.println( "Match and break from here");break outerSwitch; //break with label case 2: System.out.println("No match for this constant"); break;}//end inner switch statement case 6: System.out.println("Case 6 in outer switch"); default: System.out.println("Default in outer switch");}//end outer switch statement System.out.println("Beyond switch statements");}//end main }//End switch1 class.

The modified program in Listing 7 uses a labeled break statement in the code group for case 1 whereas the original program in Listing 6 has an unlabeled break in that position.

By comparing the output from this program with the output from the previous program, you can see that execution of the labeled breakstatement caused control to break all the way out of the labeled switch statement completely bypassing case 6 and default.

As you can see from examining the output, the labeled break statement causes the program to break all the way out ofthe switch statement which bears a matching label.

A similar situation exists when a labeled break is used in nested loops with one of the enclosing outer loops being labeled. Control willbreak out of the enclosing loop to which the labeled break refers. It will be left as an exercise for the student to demonstrate this behavior tohis or her satisfaction.

Labeled continue statements

Now consider use of the labeled continue statement. A continue statement can only be used in a loop; it cannot be used in a switch. The behavior of a labeled continue statement can bedescribed as follows: "Terminate the current iteration and continue with the next iteration of the loop to which the label refers."

Again, it will be left as an exercise for the student to demonstrate this behavior to his or her satisfaction.

The return statement

Use of the return statement

Java supports the use of the return statement to terminate a method and (optionally) return a value to the calling method.

Questions & Answers

more explanation on GDP
Isaac Reply
it is a country total out put of goods and services divided by the total population of the country.I think it can also be derived from the country labour force,,because it mostly depend on the labour force and the level of technology .
labour force and technological progress leads to greater production increases the GDP
What is economics?
Bubu Reply
by this time
It is a social science that analyses production,distribution and consumption of goods and services
A social science that study human behavior in relationship with decision making
What are the typical patterns of GDP for a high-income economy like the United States in the long run and the short run?
mwangala Reply
What are the limitation and significant of macroeconomic
Usman Reply
explain the significance of concerpt of opportunity cost in planning
Mwanaid Reply
what is meant by the price elasticity of demand?
Martine Reply
when price of a commodity increase it's demand contracts , and whe the price of a commodity decreases it's demand expands so the degree of change in demand in response to change in own price of the commodity is called PED . Ed = percentage change in quantity demanded / percentage change in price
What are the limitations of macroeconomic and their segnificant
Usman Reply
Discuss the role of competition in stimulating economic growth?
Daniel Reply
competition stimulate economic growth because in such types of economy,they is no monopoly power every supplier will want to produce to meet customers choice which brings about quality production and attract invested and customers into such economy
competition creates Monopoly because of economy of scale. it's not antithesis but different side of same coin
competition result in high economic growth since every firm will intend to provide quality services and products to meet customers needs and requirements unlike in Monopoly situation where a firm just provide what it want to resulting in large stock piles of unwanted products ,ie inefficiency, howev
microeconomics study part of the economy but macroeconomic study the whole economy
Olokun Reply
studying the whole economy, solving the problem of the economy and building up the economy
micro means small while macro means large
standard of living is the footsteps of an economy because it plays important role for country to have crucial view about their budget ,import and export
it will be differ because economic agent will only take their views on some part of household
can opportunity cost be zero
OBED Reply
how many types of transportation do we have
yes. when a customer's purchasing power is high, he may have d ability to purchase all he needs, dt makes opportunity cost zero
please can give more explanation on this question
what are the factors production
Labour capital entrepreneurs
Land,capital, labour,and the entrepreneur
I will like to know use of calculus in economics
do they use it in economics?
I want to know if I should take calculus or statistics and probability my senior year of highschool
yes for example in monopolistic competitive market..... TR=TC* & THIS CALCULATED BY CHANGING( DERIVATIVE LAW) MR =MC ** WILL BE THE FORMULA THAT USE.
please in which topic in economic is the question coming from.
from PCF in economics
why is unitary proportional to responsiveness
Etim Reply
any tip for igcse economics exam?pls
Stacey Reply
What is a market
Divine Reply
what are the variables that affect demand
what are the variables that affect demand
what are the variables that affect demand
what are the variables that affect demand
what are the variables that affect demand
price of the related goods 2 price of the given commodity 3 income of the consumer 4 taste and preference 5 expectation in the future price
pls the taste and preference
explain briefly
a consumer taste and preference commodity changes for a time the man becomes
sorry sorry
is when the price of a commodity becomes high and can't afford example Samsung instead of iPhone
consumers who have high intense for goods will purchase the goods even if the price of that commodity increases because he or she preferred that commodity.people will be prefer iphone as its price increase
as usual bad taste of preference is when a consumer regrets from one commodity to another in terms of the price
thanks alot
you're welcome
#Preference; #Income #Test
#price Of Commodity #Income #Taste #Preference
#Market is The Place Where Buyers And Sellers Are Exchanging Their Goods And service. #
difference between macro and micro economics
Microeconomic Study about individual consumers market But Macroeconomis Study General economic Process Such As #Aggregate Demand #Aggregate Supples #GDp= #GNp
nice so can u run down a brife discussion on GDP
Researchers demonstrated that the hippocampus functions in memory processing by creating lesions in the hippocampi of rats, which resulted in ________.
Mapo Reply
The formulation of new memories is sometimes called ________, and the process of bringing up old memories is called ________.
Mapo Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?