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: How is this nested for loop working!

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How is this nested for loop working!

    class Nested {
    public static void main(String args[]) {
    int i, j;
    for(i=0; i<10; i++) {
    for(j=i; j<10; j++)
    System.out.print(".");
    System.out.println();
    }
    }
    }


    The output produced by this program is shown here:
    ..........
    .........
    ........
    .......
    ......
    .....
    ....
    ...
    ..
    .


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How is this nested for loop working!

    The code would be easier to understand if it were properly formatted. The statements should be indented for nested logic (ie inside loops) and there should be {}s around the code in each loop.

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How is this nested for loop working!

    samadniz, should you have read the forums rules, you would have seen this forum is for member introductions only. You should also have seen that duplicate posts are not allowed.
    http://www.javaprogrammingforums.com...sted-loop.html
    Thread locked.

Similar Threads

  1. Having some nested loop problem
    By joel1314 in forum Loops & Control Statements
    Replies: 13
    Last Post: June 3rd, 2012, 05:04 AM
  2. Nested for loop
    By wolf_fcknHaley33 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 23rd, 2012, 08:49 AM
  3. Nid help in nested loop !!
    By Spice in forum Loops & Control Statements
    Replies: 1
    Last Post: February 14th, 2012, 11:10 AM
  4. Nested loop if statement help
    By CSUTD in forum Loops & Control Statements
    Replies: 7
    Last Post: November 8th, 2011, 02:05 PM
  5. nested loop
    By b109 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 30th, 2010, 10:05 AM