Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

question regarding nested loops

nested loop loop

  • Please log in to reply
2 replies to this topic

#1 jsnjt03

jsnjt03

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 21 September 2011 - 09:14 AM

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.

  • 0

#2 Roger

Roger

    Skadoosh!

  • Administrator
  • 1222 posts
  • Programming Language:C, PHP
  • Learning:Others

Posted 21 September 2011 - 11:45 AM

Moved to the correct forum: Java Help
Please place your posts in the correct forum moving forward.

Thanks,
Roger
  • 0

New around here? Click here to register and start participating in under a minute?

Or do a quick search and you may find the answer you're looking for.


#3 Sinipull

Sinipull

    CC Addict

  • Validating
  • PipPipPipPipPip
  • 384 posts

Posted 22 September 2011 - 12:20 AM

See this thread:
http://forum.codecal...p-examples.html

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

  • 0
.





Also tagged with one or more of these keywords: nested loop, loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download