Jump to content

question regarding nested loops

- - - - -

  • Please log in to reply
2 replies to this topic

#1
jsnjt03

jsnjt03

    Newbie

  • Members
  • Pip
  • 2 posts
I wrote this code for school and had a question about it.

	for(int j=0; j<x-2; j++)

		{

		    System.out.print("*");

		     

		     for(int k=0; k < x-2; k++)

		     {

		         System.out.print(" ");

		        

		     }

		  System .out.print("*"); 

		  System.out.println();

	    }


Why does the first loop make a column and the second loop makes a row. I just do not understand nested loops.

Thanks

Edited by Roger, 21 September 2011 - 11:46 AM.
moved + added code tags.


#2
Roger

Roger

    If nothing goes right, go left.

  • Administrators
  • 718 posts
  • Programming Language:C, PHP
  • Learning:Python
Moved to the correct forum: Java Help
Please place your posts in the correct forum moving forward.

Thanks,
Roger
Check out our update Guidelines/FAQ. When posting code, remember to use code tags - Posted Image.

#3
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
See this thread:
http://forum.codecal...p-examples.html

Edited by Sinipull, 26 September 2011 - 07:36 AM.

.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users