Académique Documents
Professionnel Documents
Culture Documents
Name: ……………………………………………..
Date:
Experiment No. 02
Aim: Write a program to print following pattern using labeled break and continue statement.
*
**
***
****
*****
Software: jdk1.6
Notepad
Theory:
This covers the following topics:
1) Break and continue statement
2) Algorithm
3) Program
4) Output
Java does not have a general goto statement. But the statements break and
continue take the place of most of uses of the goto. Java does allow any
statement to be labeled as in
Label: statement
This is useful only for those compound statements, because break and continue
can target a labeled compound statement. In this case they take the form:
break label;
continue label;
Algorithm:
Step 1: Start
Step 2: Create a class LabelTest.
Step 3: Start of a class with main method.
Step 4: Initialize a label of break and continue.
Step 5: Start a row loop.
Step 6: Check if (rows==6) jump to break label.
Step 7: Start a column loop.
Step 8: Check if (column>row) jump to continue label.
Else print the pattern.
Step 9: Stop.
Program:
class LabelTest
{
public static void main(String args[])
{
stop: {
nextRow:
for(int row=1;row<=7;row++)
{ if (row==6)
break stop;
System.out.println();
for(int column=1;column<=10;column++)
{
if(column>row)
continue nextRow;
System.out.print(" * ");
}
}
}
}
}
Output:
Conclusion: Thus we have studied and performed Labeled continue and break jump
statements.