7. Control flow statements:

 The control flow statements,which can helps you the troll and define the flow of execution in a program.
      Java providing three types of control flow statement :
    Decision making statements
    Loops statements
    Jump statements

* Decision-making statements:
      It evaluate the Boolean expression and controls the flow of execution of program.
  There are two types in it;They are: if statements and Switch satements.

.If statements:
  It is used to evaluate a condition .It checks the progrgam is either or false.
There are four types of If satements.They are:
(1) If statement
(2) If-else satement
(3) Else-if statement
(4) Nested if-else statement

(1) If statements:
 It is most basic statement,when compared to all statements. It evaluates the given program is true or false.If it is true, then it is executes.
   
 program:
  package star code learns;
public class student{
public static void main(string[]args){
 int x=10;
 int y=12;
 if(x+y>20){
system.out.println("x+y is greater than 20");
     }
  }
}
OUTPUT: x+y is greater than 20.

(2) If-else satement:
    It is extension of if statement.In these the else block will be executed while the if block conditiion is false.

program:
 package star code learns;
public class Tutorial {
public static void main (string[]args){
 int x=10;
 int y=12;
if(x+y<10){
system.out.println("x+y is less than 10");
 }
else {
system.out.println("x+y is greater than 20");
   }
}
OUTPUT:x+y is greater than 20.

(3) Else-if statements:
   We can say that, the else-if statement is a chain of if-else statement.It creates a decision tree where the code may enter and may exit.

program:
 package star code learns;
public class Tutorial{
public static void main(string[]args){
String city = "Tamil Nadu";
if(city == "chennai"){
system.out.println("city is chennai");}
else if(city == "tirupati"){
system.out.println("city is tirupati");}
  }
}

OUTPUT: Tamil Nadu

(4) Nested if-statement:
 The if-statement contains contains multiple of if-else statements as a block of code.

program:
package star code learns;
public class students{
public static void main(string[]args){
String address = "Puttur,Andra Pradesh";
if(address.ends With("Andra pradesh")){
if(address.contains("Siddarth college"));
  }
else if(address.contains("SITAMS college")){
system.out.println("Your college is SITAMS");
 }
else {
 system.out.println("You are not living Andra Pradesh");
   }
 }
}

OUTPUT:PUttur.

Switch statement:
 This statement is similar to if-else-if statemnets.If the variable for the range of values defined for multiple case statements.

program:
package star code learns;
public class Tutorial implements Cloneable {
public static void main(string[]args){
  int num = 2;
  Switch (num){
 case 0;
 system.out.println("number is 0");
 break;
 case 1; 
 system.out.println("number is 1");
 break ;
 default:
system.out.println(num);
   }
  }
}
OUTPUT: 2.

*Loop statements:
 Sometimes we need to execute,block of codes repeatedly.Such time condition evaluates to true.Here ,loop statements are used to execute set of instructions in a repetedly at a time.The execution of the program depends upon the particular condition.
  In java, we will see three types of loops that executes in same manner.
(1) For loop
(2) while loop
(3) do-while loop

(1) For loop:
For loop is similar like in c and c++.It indicates,to initialize the loop variable,checks the condition and increment/decrement in a single line of a code.

syntax:
for(initilaisation,condition,increment/decrement){
// statements;
     }

program:
package star code learns;
public class For Loop{
public static void main(string[]args){
 int sum = 0;
 }
system.out.println("the sum of first 11 natural numbers is " + sum);
   }
}
OUTPUT:
 The sum of first 11 natural numbers is 66.

(2) While Loop:
 It is also known as pre-tested looop.A while loop allows a part of the code to be executed.

syntax:
while(condition){
 // statement;
  }

program:
 package star code learns;
public class While Loop{
public static void main(string[]args){
  int 
i = 0;
system.out.println ("printing the list of first 8 even numbers \n");
 while(i<=8){
system.out.priintln(i);
 i = i+2;
    }
  }
}
OUTPUT
printing the list of 8 even numbers
   0
   2
   4
   6
   8

(3) Do-while loop:
  It is a post-tested loop.Using this statemnet, we can repeat the code execution of several parts of the statement.It is used ,only where we need to execute the loop at least once. 

Syntax:
Do{
//statement;
}
While (condition)

Program:
Package star code learns;
Public class Do-while Loop{
Public static void main(string[]args){
  int = 0;
syetem.out.println("printing the list of first 6 even numbers \n");
do {
 syetem.out.println(i);
   i= i+2;
}
while(I<=6);
  }
}

OUTPUT:
printing the list of first 6 even numbers. 
     0
     2
     4
     6 
* Jump statements :
    It is used to transfer the control of the program to the specific statement.
There are two types of jump statements ;
They are :
1 . Break and
2 . Continue 

1 . Break statements :
It is used to break the current flow of the programme
and transfer the control to the next statement outside the current flow . Also used to break the loop and switch statements . 
 It cannot be used independently in the Java programme.
Program :
package star code learns;
public class Break Example {
public static void main (string []args){
for (int i=0 ; i<=12 ; i++){
system.out.println(i);
if (i==8){
break;
}
}
}
}

Output :
0
1
2
3
4
5
6
7
8


2 . Continue statement :
It is not like as break statement . The continue statement does not break the loop , it only steps the specific part of the loop and jumps to the next loop immediately.
Program :
package star code learns ;
public class Continue Example {
public static void main (string [] args){
for (int i=0 ; i<=2 ; i++){
if ( j==4){
Continue;
}
System.out.println(j);
}
}
}
}
Output :
0
1
2
3
5
1
2
3
5
2
3