SunQuest
 
       Java
  Home arrow Java arrow Page 5 - Java Statements
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Java Statements
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2007-10-24

    Table of Contents:
  • Java Statements
  • While Loop
  • Do-While
  • For Loop
  • To Be Continued...

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    Java Statements - To Be Continued...


    (Page 5 of 5 )

    No, it's not the end of the article just yet (grumble grumble). The Continue statement allows you to force an early iteration of the loop. Basically it runs a portion of the loop without executing the rest of the code in the body. Here is a sample:


    class Counter {

    public static void main(String args[]) {

    for(int timer = 0; timer < 10; timer ++) {

    System.out.print(timer + “ “);

    if (i%5 == 0) continue;

    System.out.println.(“”);

    }

    }

    }

    The above code will print five numbers on a line up to the number 10 like so:

      0 1 2 3 4 5

      6 7 8 9

    The Return of the Jedi

    I just wanted to throw that in there. The Return statement is used when you wish to return from a method (we will discuss methods later on). Here is how that looks in code:


    class ChickenEgg {

    public static void main(String args[]) {

    boolean t = true;

    System.out.println(“The chicken!”);


    if(t) return;


    System.out.println(“The egg!”);


    }

    }

    The above code will print out: The Chicken! as it forces a return from the method prior to it, executing the second System.out.println command, thus solving the age old question: what came first, the chicken or the egg?

    Incidentally, neither of those is right. The correct answer is a pre-evolved version of the chicken.

    Well that's it for this tutorial. Be sure to join me for the next article, when I will help teach you to become a true Java ninja.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article discusses Java Statements, like the If statement and Loops (such as the...
     

       

    JAVA ARTICLES

    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway