Control Statements-Java

As we have discussed earlier, syntax of Java is similar to C/ C++. Therefore all the control statements are same.
if, if-else, switch-case, for, while, do-while with 'break' and 'continue' keywords.
e.g.:


if(x>y)
{
statement 1;
statement 2;
}
if(x>y && x>z)
{
statement 1;
statement 2;
}
else
{
statement 3;
statement 4;
}
In switch case you can use byte,short,int,long,char and String Data type as switch case variable.
switch(x)
{
    case 1:
      statement 1;
      statement 2;
      break;
   case 2:
      statement 3;
      statement 4;
      break;
   default:
      statement 5;
      statement 6;
}
for(int i=1;i<=10;i++)
{
   statement 1;
   statement 2;
   statement 3;
}
while(x>y)
{
   statement 1;
   statement 2;
   statement 3;
}
do
{
   statement 1;
   statement 2;
   statement 3;
}while(x>y);
There is one extra loop in Java known as Collection Loop. You can use this loop to access the values of an array.But note that you can't change the contents of the array using this loop.
int arr[]={43,6,8,3,5,7,56,2};
for(int item:arr)
{
   use 'item' variable to access the values of the array in sequence.
   You can use any name, 'item' is not the keyword/compulsory.
   Declare the data type of 'item' same as the data type of array elements
}