import javax.swing.JOptionPane; public class Java_Break_Out_Of_For_Loop { public static void main(String args[]){ int i = 0; String strb = "break", strc = "continue", choice = ""; JOptionPane.showMessageDialog(null, "Tip of the day.. \n\tAllow the label 'break' to close 'for' loop", "Welcome to roseindia message zone", 1); roseindia: for (;; i++) { choice = JOptionPane.showInputDialog(null, "Type break to terminate the loop\n or Type continue to carry on inside the loop", "Input option box", 2); if(choice.equals(strb)){ JOptionPane.showMessageDialog(null, "You are now out of ' for ' loop\n under label roseindia", "Break Label ", 1); break roseindia; } else if(choice.equals(strc) ){ JOptionPane.showMessageDialog(null, "You are now at the beginning of the loop\n You have continued the loop", "Continue Label", 1); continue roseindia; } else { JOptionPane.showMessageDialog(null, "Press enter to continue", "Label does not match ", 0); continue roseindia; } } } }