Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: loop in java

  1. #1
    Banned
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default loop in java

    for Loops
    A for loop is used to repeat a statement until a condition is met.

    for (initialization; test; increment) {
    statement;
    }

    while Loops
    The while loop repeats a statement for as long as a particular condition remains true.
    Here’s an example:
    while (a<3) {
    x = x * a++; // the body of the loop
    }

    do-while Loops
    The do loop is just like a while loop with one major difference—the place in the loop
    when the condition is tested.
    A while loop tests the condition before looping, so if the condition is false the first
    time it is tested, the body of the loop never executes.
    A do loop executes the body of the loop at least once before testing the condition, so if
    the condition is false the first time it is tested, the body of the loop already will have
    executed once.
    Example
    int a=1;
    do {
    a *= 3;
    System.out.print(a + “ “);
    } while (a < 30);


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,197
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: loop in java

    Are you writing a tutorial or do you have a question?

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: loop in java

    OTN Discussion Forums : User Profile for 877493
    All about casperl roh

Similar Threads

  1. loop in java
    By jonnitwo in forum Loops & Control Statements
    Replies: 4
    Last Post: July 8th, 2011, 02:13 PM
  2. Java Do..while loop problem
    By jwill22 in forum Loops & Control Statements
    Replies: 4
    Last Post: November 13th, 2010, 03:02 AM
  3. problems with loop in Java App
    By dmonx in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 03:13 PM
  4. for loop in java
    By kissmiss in forum Loops & Control Statements
    Replies: 1
    Last Post: December 16th, 2009, 02:47 AM
  5. JAVA for loop
    By tazjaime in forum Loops & Control Statements
    Replies: 2
    Last Post: August 18th, 2009, 07:43 PM