Control statement

 



If statement in Java

  • It is used to test the condition.
  • If the condition is true its body will execute otherwise does not execute.



If else statement in Java

  • It is used to test the condition.
  • If the condition is true body of if will execute otherwise body of else execute.


If else if ladder statement in Java 




  • It is used to test the condition.
  • If executes only one condition at a time.
  • The condition which is true first from the top will execute.



Nested if statement in Java


  • It is used to test the condition.
  • One if inside another if is called nested if.


Switch statement in Java

  • Switch statement allows us to execute one statement from many statement and the statements are called case.
  • Inside the body of switch there are a number of cases and there is a single number is passed at the place of parameter to select and execute a case.
  • In the switch statement a value/number is passed in the place of parameter and the case from which the parameter is matched is executed.
  • If no case matched with parameter then default case will execute.




Loop in Java

  • Loop is a part of control flow statements.
  • To run the particular block of code continuously until a required condition is fullfil is called looping.
  • Loop is used when there is a need to execute a part of program multiple times.


 
  • There is a control variable, called the loop counter.
  • The control variable must be initialized; in other words, it must have an initial value.
  • The increment/decrement of the control variable, which is modified each time the iteration of the loop occurs.
  • The loop condition that determines if the looping should continue or the program should break from it.   

For loop in Java



  • In for loop there are three part initialization,condition and increment/decrement.
  • Initialization part executes only once.
  • Condition part defines the condition for the execution of code block.
  • All the three part of for loop are optional.

While loop in Java

  • It's body will execute until the given condition is true.

Do while loop in Java

  • It's body will execute until the given condition is true


Jump Statement in Java ?

  • It is used to transfer the control from one point to another point in the program.
  • There are three jump statements are used in java.
  • break statement
  • continue statement
  • return statement

break statement

  • It is used to transfer the control out of the body of loop.
  • In other word we can say that it terminates the current loop.
  • break statement are mostly used with loop(for,while,do while) and switch statement.
  Syntax :- 
      
      break;

continue statement

  • It is used to skip the next statement and continue the loop.
  • continue statement are mostly used with loop(for,while,do while).
  
   Syntax :- 
      
      continue;

return statement

  • return statement terminates the current function and transfer the control to the calling function.
  • we can also use return statement to trasfer value from one function to another.
      Syntax :- 
      
      return;

Post a Comment

0 Comments