Home Java Java Control Statements



Java Control Statements
Posted on: April 3, 2006 at 12:00 AM
In this section, we are going to discuss the control statements. Different types of control statements: the decision making statements (if-then, if-then-else and switch), looping statements (while, do-while and for) and branching statements (break, continue and return).

Java Control Statements

     

  1. Introduction to Control Statements
    In this section, we are going to discuss the control statements. Different types of control statements: the decision making statements (if-then, if-then-else and switch), looping statements (while, do-while and for) and branching statements (break, continue and return).
      
  2. Selection Statements
    1. if
      The if statement: To start with controlling statements in Java, lets have a recap over the control statements in C++. You must be familiar with the if-then statements in C++. The if-then statement is the most simpler form of control flow statement.
        
    2. if-else
      The "if-else" statement is an extension of if statement that provides another option when 'if' statement evaluates  to "false" i.e. e lse block is executed if "if" statement is false.
        
    3. Switch
      Sometimes it becomes cumbersome to write lengthy programs using if and if-else statements. To avoid this we can use Switch statements in Java.
        
  3. Loop Statements
    1. while
      Lets try to find out what a while statement does. In a simpler language, the while statement continually executes a block of statements while a particular condition is true.
        
    2. do-while
      It will enter the loop without checking the condition first and checks the condition after the execution of the statements. That is it will execute the statement once and then it will evaluate the result according to the condition. 
       
    3. for
      The concept of Iteration has made our life much more easier. Repetition of similar tasks is what Iteration is and that too without making any errors. Until now we have learnt how to use selection statements to perform repetition.
        
  4. Transfer statements
    1. break
      Sometimes we use Jumping Statements in Java. Using for, while and do-while loops is not always the right idea to use because they are cumbersome to read.
        
    2. continue
      Continue statement is just similar to the break statement in the way that a break statement is used to pass program control immediately after the end of a loop and the continue statement is used to force program control back to the top of a loop. 
        
    3. return
      It is a special branching statement that  transfers the control to the caller of the method. This statement is used to return a value to the caller method and terminates execution of method.
        
    4. try-catch-finally

Related Tags for Java Control Statements:


More Tutorials from this section

Ask Questions?    Discuss: Java Control Statements   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.