Computersight > Programming > Java

Loops in Java

Learn to create loops in java. Like Do While, While, and For loops.

Loops in java are very simple, as are all other loops in the other languages. There are three types of loops Do While, While, and For. First let's look at the Do While loop.

Starting from the beginning you set up the class, then the method. Next declare the variable that you start with. Then the Do statement starts, it prints out “The number is” then the variable that you started with, and ends with a count up method for the starting variable. At the end of the loop the while statement indicates an if statement that when your starting variable is less than or equal to 100, then it stops the loop.

This second type of loop is called a For loop.

Starting off you set up the class and a method like the Do While loop. Now inside the for method contains a declared variable, then the conditional (for example if “i” is less than or equal to 10 then the loop will end), next the i++ is the increment of +1 to the variable i. For every time this loop executes the output should be “The number is" then the variable.

Now last but not least the While loop.

One of the simplest loop is the While loop. First make the class and method. Next you set up variable like the Do_While. Then the while statement declares if “i” is less than or equal to 10. The output would be “The number is” plus the variable, then the variable increases by one(using the i++ statement).

30
Liked It
I Like It!
Related Articles
Loops in Blitz  |  The Generic for Loop
More Articles by EmoSniper
TI.83 Plus 1  |  TI 83 Plus Programming
Latest Articles in Java
The Basics of Java Programming 1  |  Basic Java
Comments (3)
#1 by idk_name, Oct 26, 2007
nice article!
#2 by geek6456, Oct 26, 2007
nice screens what you use JCreator
#3 by ok_dude, Oct 26, 2007
what sup
Post Your Comment:
Name:  
Copy the code into this box:  
Inside Computersight

Communication & Networks

 /

Computers

 /

Hardware

 /

Operating Systems

 /

Programming

 /

Software


Popular Tags
Popular Writers
Computersight
About Us
Terms of Use
Privacy Policy
Services
Submit an Article
Advertise with Us
Contact

© 2007 Copyright Stanza Ltd. All Rights Reserved.