Branching Statements

Java Control Flow Statements

break Statement
/*  break Statement Example  */
/*  Save with file name BreakStatement.java  */

public class BreakStatement
{
	public static void main(String args[])
	{
		System.out.println();
		System.out.println("break Statement Example ");
		System.out.println("=======================");
		System.out.println();

		int count = 10;
		while(true) //INFINIT LOOP
		{
			if(count == 0)
				break;
			System.out.println(count);
			count--;
		}
	}
}
                        
continue Statement
/*  continue Statement Example  */
/*  Save with file name ContinueStatement.java  */

public class ContinueStatement
{
	public static void main(String args[])
	{
		System.out.println();
		System.out.println("continue Statement Example ");
		System.out.println("==========================");
		System.out.println();

		int count = 1;
		while(count<=100)
		{
			if(count <= 10)
			{
				System.out.println(count);
				count++;
				continue;
			}
			else
			{
				break;
			}
		}
	}
}
                        
return Statement
/*  return Statement Example  */
/*  Save with file name ReturnStatement.java  */

public class ReturnStatement
{
	public static void main(String args[])
	{
		System.out.println();
		System.out.println("return Statement Example ");
		System.out.println("========================");
		System.out.println();
		int max = getMaximumNumber(10, 20);
		if(max==0)
			System.out.println("Equal Numbers");
		else
			System.out.println("Max Number is : " + max);
	}

	//METHOD
	public static int getMaximumNumber(int x, int y)
	{
		if(x > y)
			return x;
		else if(x < y)
			return y;
		else
			return 0;
	}
}