Java Break command is commonly used in terminating looping statements. break command comes under the Java branching statements category. In programming it is widely used by programmers for breaking loops like 'for', 'while' etc.
Java Break command
Java Break command is commonly used in terminating looping statements. break
command comes under the Java branching statements category. In programming it is
widely used by programmers for breaking loops like 'for', 'while' etc. . break
is often used with label continue, which also comes under Java branching
statements category but works just opposite to break. break brings the program
control out of the outermost loop whereas continue returns the program control from the line at which the
continue label is passed at the beginning of the outermost loop for
re-processing.
Break Command in Java Example
import javax.swing.*; public class Java_Break_command { public static void main(String args[]) { String str = "roseindia", choice = ""; boolean self = true; way: do{ choice = JOptionPane.showInputDialog(null, "\tEnter string", "String Input First chance", 1); if (choice.equals(str)) { JOptionPane.showMessageDialog(null, "Rigth entry\n\t\tCongratulations" , "\t\t\t\t\t\tHurray....", 2); break; } else if(!(choice.equals(str))){ JOptionPane.showMessageDialog(null, "wrong entry\n\t\t\ttry again", "\t\t opps...", 0); choice = JOptionPane.showInputDialog(null, "\tEnter string", "String Input Last Chance", 1); if (choice.equals(str)) { JOptionPane.showMessageDialog(null, "Rigth entry\n\t\tCongratulations" , "\t\t\t\t\t\tHurray....", 2); break; } else if(!(choice.equals(str))) { JOptionPane.showMessageDialog(null, "get the rigth entry\n and then restart the program", " oops Session time out", 0); break; } } }while(self); } } |