Home arrow Java arrow Page 5 - Java Part 2: Syntax

Java Part 2: Syntax

In this, part two of this ten part series on Java, Chris looks at the Java language syntax, variable declerations, truth conditions, loops and more. He finishes by wrapping everything up into a simple Java function.

Author Info:
By: Chris Noack
Rating: 5 stars5 stars5 stars5 stars5 stars / 9
November 27, 2001
  1. · Java Part 2: Syntax
  2. · Decleration and assignment
  3. · Making code more readable
  4. · Truth operations
  5. · Iterations and looping
  6. · The while loop
  7. · Putting it all together
  8. · Conclusion

print this article

Java Part 2: Syntax - Iterations and looping
(Page 5 of 8 )

Iterations follow the same language formation as those in C and C++.

The for loop

The for loop contains a header and body. The header is as follows:

(initializing statement; condition; statement to execute)


// code to execute if condition is true


Initializing statement:

The initializing statement sets up any variables or conditions which are needed by the loop.


The condition must evaluate to true / false and can be any expression that does. If it evaluates to true, then the following statement is executed and the body of the loop is also executed.

Statement to execute:

Executed if the previous conditional statement evaluates to true.

Loop body:

Executed if the previous conditional statement evaluates to true. If not, the entire body is skipped.

Here is a simple for loop:

for( int i = 0 ; i < 100 ; i++ )


// perform some action


Note that a for loop always needs two semi-colons as part of its header to avoid a compilation error. These semicolons do not necessarily need assignments, truth tests or incrementing statements between them but the colons must be present. Indenting the body code is also a must when using for loops.


{ }

The code above would iterate indefinitely.
blog comments powered by Disqus

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials