Home arrow Java & J2EE arrow Page 4 - Java Statements

For Loop - Java

In our last article, we finished our discussion of Java operators, and started to take a look at statements. In this article, we'll continue explaining Java statements. Statements aren't exactly complicated once you grasp the concept. Indeed, many statements have counterparts -- of a sort -- in real life.

  1. Java Statements
  2. While Loop
  3. Do-While
  4. For Loop
  5. To Be Continued...
By: James Payne
Rating: starstarstarstarstar / 13
October 24, 2007

print this article



The For Loop allows you to condense the code used in While loops. If we wanted to rewrite our NASA launch code with a For loop, it would look something like this (hit it!):

(Note: the writer of this article has listened to the Beastie Boys one too many times)

class LaunchCode {

public static void main(String args[]) {

int timer;

for(timer = 10; timer > 0; timer—)

System.out.println(“T minus “ + timer);



This would result in the same countdown as our previous NASA program. As a side note, you could technically initialize the timer variable inside the For loop. If you had done so, you would not be able to call it outside of the loop. Placing the variable outside the loop allows the variable to be called again later on.

Jump Statements

There are three types of Jump statements in Java: the break, the continue, and the return. We have already used the break statement in some of our previous code. It's function is pretty simple: it terminates a statement, exits a loop, or can be used as a goto statement. Since we have already used it several times, I won't discuss it any further. 

>>> More Java & J2EE Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: