/***************************************************************
 ** This Java program to illustrates BREAK, CONTINUE and RETURN
 ** statements within the following loops: for, while and do while
 ***************************************************************/
import java.io.*;

public class BreakContinueReturn
{
  public BreakContinueReturn()
    {
      int     LoopCounter = 0;
      String  StringToReadKeyBoard;
      char     Respondchar = 'B';


      System.out.println("\n***************** For loop *************\n");
      for( ; ; )
        {
          System.out.println("\nThis an Infinite FOR Loop");
          System.out.println("To exit out this loop enter any of the following");
          System.out.println("\"B\" or \"b\" or any key to break");
          System.out.println("\"C\" or \"c\" to continue");
          System.out.println("\"R\" or \"r\" to end this program");
          System.out.print("Enter a Char then press ENTER ====> ");
          Respondchar = (char)ReadCahrFromKeyBoard();
          if( ('B' == Respondchar) || ('b' == Respondchar))
              break;
          else
            if( ('R' == Respondchar) || ('r' == Respondchar))
              return;
            else
              continue;
        }
      System.out.println("\n***************** While loop *************\n");
      while(true)
        {
          System.out.println("\nThis an Infinite WHILE Loop");
          System.out.println("To exit out this loop enter any of the following");
          System.out.println("\"B\" or \"b\" or any key to break");
          System.out.println("\"C\" or \"c\" to continue");
          System.out.println("\"R\" or \"r\" to end this program");
          System.out.print("Enter a Char then press ENTER ====> ");
          Respondchar = (char)ReadCahrFromKeyBoard();
          if( ('B' == Respondchar) || ('b' == Respondchar))
            break;
          else
            if( ('R' == Respondchar) || ('r' == Respondchar))
              return;
            else
              continue;
        }
      System.out.println("\n***************** Do While loop *************\n");
      do
        {
          System.out.println("\nThis an Infinite DO WHILE Loop");
          System.out.println("To exit out this loop enter any of the following");
          System.out.println("\"B\" or \"b\" or any key to break");
          System.out.println("\"C\" or \"c\" to continue");
          System.out.println("\"R\" or \"r\" to end this program");
          System.out.print("Enter a Char then press ENTER ====> ");
          Respondchar = (char)ReadCahrFromKeyBoard();
          if( ('B' == Respondchar) || ('b' == Respondchar))
            break;
          else
            if( ('R' == Respondchar) || ('r' == Respondchar))
              return;
            else
              continue;
        } while (true);
    }
  /****************************************************/
  int ReadCahrFromKeyBoard()
  {
    int   InputByte;
    int   InputByte_2;

    try
    {
       InputByte    = System.in.read();
       // skip carriage return
       if(   ('\n' == InputByte)
         ||  ('\r' == InputByte)
         )
         InputByte    = System.in.read();
    }
    catch(IOException MyIOException)
    {
      return (0);
    }
    // skip carriage return
    InputByte_2 = InputByte;
    while(  (InputByte_2 != '\n')
        &&  (InputByte_2 != '\r')
         )
    {
      try
      {
        InputByte_2 = System.in.read();
      }
      catch(IOException MyIOException)
      {
        return (0);
      }
    }
    return(InputByte);
  }
  //*******************************************************
  public static void main(String [] args)
  {
    BreakContinueReturn MyBreakContinueReturn
          = new BreakContinueReturn();
	 try
	 {
		 int returnKey;
		 returnKey =  System.in.read();
		 if(   ('\r' == returnKey)
			|| ('\n' == returnKey)
			)
		   System.in.read();
	 }
	 catch(Exception MyException)
	 {
		 //do nothing
	 }
  }
}
