SlideShare a Scribd company logo
18CS653: Programming in Java
Topic: Branching Statements
Outlines
• break Statement
• continue Statement
• return Statement
[Expected Time: 1 Hours]
break Statement
 break statement has three uses:
 Terminates a statement sequence in a switch statement
Used to exit a loop
Used as a “civilized” form of goto
 The break statement has two forms:
Labeled
Unlabeled
Unlabeled break
 An unlabeled break is used to terminate a for, while, or do-while
loop and switch statement.
Example 1:
class BreakTest
{
public static void main(String agrs[])
{
for(int i=0; i<100; i++)
{
if(i == 10) break;
System.out.println("i: " + i);
}
System.out.println("Loop completed");
}
}
Example
public void switchTest() {
for(int i=0; i<5; i++)
switch(i) {
case 0:
System.out.println("i is zero."); break;
case 1:
System.out.println("i is one."); break;
case 2:
System.out.println("i is two."); break;
default:
System.out.println("i is greater than 2.");
}
}
Labeled break Statement
 Java defines an expanded form of the break statement.
break label;
 By using this form of break, we can break out of one or
more blocks of code.
 When this form of break executes, control is transferred
out of the named block.
Example
class BreakDemo{
public static void main(String [] rk)
{
outer:
for(int i=0; i<3; i++){
System.out.println("Outer "+ i);
inner:
for(int j=0; j<3; j++)
{
System.out.println("Inner "+j);
if(i== j+1)
break outer;
System.out.println("Bye");
}
}
}
}
NOTE
 The break statement terminates the labeled statement;
it does not transfer the flow of control to the label.
 Control flow is transferred to the statement immediately
following the labeled (terminated) statement.
continue Statement
 The continue statement skips the current iteration of a for,
while , or do-while loop.
 The unlabeled form skips to the end of the innermost
loop's body and evaluates the boolean expression that
controls the loop.
Example
class ContinueDemo {
public static void main(String[] rk) {
String str = “she saw a ship in the sea”;
int size = str.length();
int count = 0;
for (int i = 0; i < size; i++)
{
if (str.charAt(i) != ‘s’)
continue;
count++;
}
System.out.println(“Number of s in “+ str + “ = ”+ count); } }
Labeled continue Statement
 A labeled continue statement skips the current iteration
of an outer loop marked with the given label.
Example
class ContinueLabel {
public static void main(String [] rk) {
outer: for (int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
if(j > i) {
System.out.println(“Hi”);
continue outer; }
System.out.print(" " + (i * j));
}
}
System.out.println(“Done”); } }
return Statement
 The return statement exits from the current method, and
control flow returns to where the method was invoked.
 The return statement has two forms: one that returns a
value, and one that doesn't.
 To return a value, simply put the value (or an expression
that calculates the value) after the return keyword.
return ++count;
return Statement
 The data type of the returned value must match the type of
the method's declared return value.
 When a method is declared void, use the form of return
that doesn't return a value.
return;
Brainstorming 1
public static void main(String [] rk){
outer:
for(int i=0; i<3; i++)
{
inner:
for(int j=0; j<3; j++)
{
System.out.println(i + ", "+ j);
if(j==2) break inner;
if(i==j) continue outer;
System.out.println("Bye");
}
}
}
Brainstorming 2
class BreakTest{
public static void main(String [] rk)
{
hello:
for(int a=1; a<3; a++)
System.out.print("Hello");
int i = 1;
if(i==1)
break hello;
System.out.print("Not reachable");
}
}
Brainstorming 3
public static void main(String [] rk)
{ int n=5;
outer: for(int a=1; a<5; a++)
{ int i=0, j=0; System.out.println();
space: while(true) {
System.out.print(" "); i++;
if(i==n-a) break space; }
star: while(true) {
System.out.print(" * "); j++;
if(j==a) continue outer;
}
}
}
6_A1944859510_21789_2_2018_06. Branching Statements.ppt

More Related Content

Similar to 6_A1944859510_21789_2_2018_06. Branching Statements.ppt

شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
جامعة القدس المفتوحة
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
Chen-Hung Hu
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
Shalabh Chaudhary
 
Thread
ThreadThread
Thread
phanleson
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
CIMAP
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
Tanzeel Ahmad
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
Pathomchon Sriwilairit
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
RehmanRasheed3
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
Abhishekkumarsingh630054
 
Templates
TemplatesTemplates
Templates
Nilesh Dalvi
 
Control statements
Control statementsControl statements
Control statements
raksharao
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
Nested loops
Nested loopsNested loops
Nested loops
Neeru Mittal
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
Svetlin Nakov
 
Exception handling
Exception handlingException handling
Exception handling
Prafull Johri
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
HongAnhNguyn285885
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
Fraz Bakhsh
 
Java Day-5
Java Day-5Java Day-5
Java Day-5
People Strategists
 

Similar to 6_A1944859510_21789_2_2018_06. Branching Statements.ppt (20)

شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Thread
ThreadThread
Thread
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
Templates
TemplatesTemplates
Templates
 
Control statements
Control statementsControl statements
Control statements
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Nested loops
Nested loopsNested loops
Nested loops
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
 
Exception handling
Exception handlingException handling
Exception handling
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
 
Java Day-5
Java Day-5Java Day-5
Java Day-5
 

More from RithwikRanjan

A1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.pptA1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.ppt
RithwikRanjan
 
INTERNSHIP PRESENTATION.pptx
INTERNSHIP PRESENTATION.pptxINTERNSHIP PRESENTATION.pptx
INTERNSHIP PRESENTATION.pptx
RithwikRanjan
 
internship.pptx
internship.pptxinternship.pptx
internship.pptx
RithwikRanjan
 
AM.pptx
AM.pptxAM.pptx
AM.pptx
RithwikRanjan
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
sam_technical_seminar.pptx
sam_technical_seminar.pptxsam_technical_seminar.pptx
sam_technical_seminar.pptx
RithwikRanjan
 
sam_report.pptx
sam_report.pptxsam_report.pptx
sam_report.pptx
RithwikRanjan
 
TQM-Module 5.pptx
TQM-Module 5.pptxTQM-Module 5.pptx
TQM-Module 5.pptx
RithwikRanjan
 
CIM MODULE 2.pptx
CIM MODULE 2.pptxCIM MODULE 2.pptx
CIM MODULE 2.pptx
RithwikRanjan
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
RithwikRanjan
 
0_A1590026209_21789_20_2018_0 Lecture.ppt
0_A1590026209_21789_20_2018_0 Lecture.ppt0_A1590026209_21789_20_2018_0 Lecture.ppt
0_A1590026209_21789_20_2018_0 Lecture.ppt
RithwikRanjan
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
RithwikRanjan
 
A1869984431_21789_28_2018_Abstract Class.ppt
A1869984431_21789_28_2018_Abstract Class.pptA1869984431_21789_28_2018_Abstract Class.ppt
A1869984431_21789_28_2018_Abstract Class.ppt
RithwikRanjan
 

More from RithwikRanjan (13)

A1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.pptA1771937735_21789_14_2018__16_ Nested Classes.ppt
A1771937735_21789_14_2018__16_ Nested Classes.ppt
 
INTERNSHIP PRESENTATION.pptx
INTERNSHIP PRESENTATION.pptxINTERNSHIP PRESENTATION.pptx
INTERNSHIP PRESENTATION.pptx
 
internship.pptx
internship.pptxinternship.pptx
internship.pptx
 
AM.pptx
AM.pptxAM.pptx
AM.pptx
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
sam_technical_seminar.pptx
sam_technical_seminar.pptxsam_technical_seminar.pptx
sam_technical_seminar.pptx
 
sam_report.pptx
sam_report.pptxsam_report.pptx
sam_report.pptx
 
TQM-Module 5.pptx
TQM-Module 5.pptxTQM-Module 5.pptx
TQM-Module 5.pptx
 
CIM MODULE 2.pptx
CIM MODULE 2.pptxCIM MODULE 2.pptx
CIM MODULE 2.pptx
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
 
0_A1590026209_21789_20_2018_0 Lecture.ppt
0_A1590026209_21789_20_2018_0 Lecture.ppt0_A1590026209_21789_20_2018_0 Lecture.ppt
0_A1590026209_21789_20_2018_0 Lecture.ppt
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
A1869984431_21789_28_2018_Abstract Class.ppt
A1869984431_21789_28_2018_Abstract Class.pptA1869984431_21789_28_2018_Abstract Class.ppt
A1869984431_21789_28_2018_Abstract Class.ppt
 

Recently uploaded

一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
thezot
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
APNIC
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
APNIC
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
Tarandeep Singh
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
3a0sd7z3
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
k4ncd0z
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
Donato Onofri
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
rtunex8r
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
3a0sd7z3
 

Recently uploaded (12)

一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
 

6_A1944859510_21789_2_2018_06. Branching Statements.ppt

  • 1. 18CS653: Programming in Java Topic: Branching Statements
  • 2. Outlines • break Statement • continue Statement • return Statement [Expected Time: 1 Hours]
  • 3. break Statement  break statement has three uses:  Terminates a statement sequence in a switch statement Used to exit a loop Used as a “civilized” form of goto  The break statement has two forms: Labeled Unlabeled
  • 4. Unlabeled break  An unlabeled break is used to terminate a for, while, or do-while loop and switch statement. Example 1: class BreakTest { public static void main(String agrs[]) { for(int i=0; i<100; i++) { if(i == 10) break; System.out.println("i: " + i); } System.out.println("Loop completed"); } }
  • 5. Example public void switchTest() { for(int i=0; i<5; i++) switch(i) { case 0: System.out.println("i is zero."); break; case 1: System.out.println("i is one."); break; case 2: System.out.println("i is two."); break; default: System.out.println("i is greater than 2."); } }
  • 6. Labeled break Statement  Java defines an expanded form of the break statement. break label;  By using this form of break, we can break out of one or more blocks of code.  When this form of break executes, control is transferred out of the named block.
  • 7. Example class BreakDemo{ public static void main(String [] rk) { outer: for(int i=0; i<3; i++){ System.out.println("Outer "+ i); inner: for(int j=0; j<3; j++) { System.out.println("Inner "+j); if(i== j+1) break outer; System.out.println("Bye"); } } } }
  • 8. NOTE  The break statement terminates the labeled statement; it does not transfer the flow of control to the label.  Control flow is transferred to the statement immediately following the labeled (terminated) statement.
  • 9. continue Statement  The continue statement skips the current iteration of a for, while , or do-while loop.  The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop.
  • 10. Example class ContinueDemo { public static void main(String[] rk) { String str = “she saw a ship in the sea”; int size = str.length(); int count = 0; for (int i = 0; i < size; i++) { if (str.charAt(i) != ‘s’) continue; count++; } System.out.println(“Number of s in “+ str + “ = ”+ count); } }
  • 11. Labeled continue Statement  A labeled continue statement skips the current iteration of an outer loop marked with the given label.
  • 12. Example class ContinueLabel { public static void main(String [] rk) { outer: for (int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(j > i) { System.out.println(“Hi”); continue outer; } System.out.print(" " + (i * j)); } } System.out.println(“Done”); } }
  • 13. return Statement  The return statement exits from the current method, and control flow returns to where the method was invoked.  The return statement has two forms: one that returns a value, and one that doesn't.  To return a value, simply put the value (or an expression that calculates the value) after the return keyword. return ++count;
  • 14. return Statement  The data type of the returned value must match the type of the method's declared return value.  When a method is declared void, use the form of return that doesn't return a value. return;
  • 15. Brainstorming 1 public static void main(String [] rk){ outer: for(int i=0; i<3; i++) { inner: for(int j=0; j<3; j++) { System.out.println(i + ", "+ j); if(j==2) break inner; if(i==j) continue outer; System.out.println("Bye"); } } }
  • 16. Brainstorming 2 class BreakTest{ public static void main(String [] rk) { hello: for(int a=1; a<3; a++) System.out.print("Hello"); int i = 1; if(i==1) break hello; System.out.print("Not reachable"); } }
  • 17. Brainstorming 3 public static void main(String [] rk) { int n=5; outer: for(int a=1; a<5; a++) { int i=0, j=0; System.out.println(); space: while(true) { System.out.print(" "); i++; if(i==n-a) break space; } star: while(true) { System.out.print(" * "); j++; if(j==a) continue outer; } } }