Java 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).

Ads

Tutorials   
How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner Java Programming Examples Read file line by line in Java 8 What are the benefits of learning Java Programming? A brief history and future of Java programming language Importance of Java for Mobile Application Development How To Become A Good Software Developer? Learn Java Programming for beginners 5 Reasons Java is Still a Great Language to Boost Your Career Prospect as a Programmer How to learn Java with no programming experience? How to learn Java? What are Classes and Interfaces in Java? Converting a String to Integer in Java How to check if a string exists in a string in JavaScript? Installing JDK 8 on Windows 10 and configuring the settings Video Tutorial of reading file in Java 9 Invincible Reasons to learn Java New to Java programming Java Programming Tips, Articles and Notes How to download JDK 1.6? Encapsulation in Java Programming How to format number in Java? Generics Example Program in Java Java 9 Features Java 9 Tutorial, news and examples How to read content of JPEG file in Java? Image Processing Tutorials in Java Programming Language Introduction to Java Technology Java 8 Consumer Interface with forEach Loop Introduction to Generics in Java Java 8 consumer class(interface) example Oracle Launches Project Valhalla for Java How to read properties file in Java? How to add JDK 8 support in Eclipse? Java 8: Java 8 is officially released and it can be downloaded How to Invoke method using Reflection API of Java? First Lambda Expressions in Java Java 8 expected release date

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. else 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

Advertisements

Ads
Share on Google+Share on Google+

Java Control Statements

Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Java Control Statements   View All Comments

Post your Comment


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

Ads

 

Ads