•

### Recent Blog Entries

If you're reading this, you're on my profile and I know you're on my profile because I'm probably viewing yours.

• Poe

Finally (and hopefully) i'm getting a team together that knows a little of this and a little of that; and maybe all my open source projects that are half written can begin to be released. :)

• Alexander

Off on a big hike, recommended to invigorate the mind between computing! \$oxygen++

# Nested For Loop [EXAMPLES!]

nested loop for loop loop

105 replies to this topic

### #97 KJGino

KJGino

CC Devotee

• Senior Member
• 424 posts
• Location:Chicago
• Programming Language:C, Java, C++, PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Transact-SQL
• Learning:Python, Assembly

Posted 21 March 2014 - 07:52 PM

ok .. thank you ..

1                      10

10                    10

--> can you solve this problem ?.. please ?..

What code have you tried for this one?

And that first code does not give the desired output.

1   2   3   4   5   6   7   8   9   10

2                                            20

3                                            30

4                                            40

5                                            50

6                                            60

7                                            70

8                                            80

9                                            90

10 20 30 40 50 60 70 80 90 100

For this one, you will need two loops -- both from 1 to 10. The outer loop will count the rows, while the inner loop will count the columns.

The first iteration is self explanatory -- from 1 to 10 and the last is the same, but each multiplied by 10.

Can you figure the ones in between?

• 0

### #98 PanjiPro

PanjiPro

CC Lurker

• New Member
• 6 posts
• Learning:Java, C++, C#, (Visual) Basic, JavaScript, Visual Basic .NET, VBScript, Others

Posted 21 March 2014 - 07:58 PM

What code have you tried for this one?

And that first code does not give the desired output.

What code have you tried for this one?

And that first code does not give the desired output.

For this one, you will need two loops -- both from 1 to 10. The outer loop will count the rows, while the inner loop will count the columns.

The first iteration is self explanatory -- from 1 to 10 and the last is the same, but each multiplied by 10.

Can you figure the ones in between?

space .. spacing .. the code is correct right ?...

• 0

### #99 KJGino

KJGino

CC Devotee

• Senior Member
• 424 posts
• Location:Chicago
• Programming Language:C, Java, C++, PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Transact-SQL
• Learning:Python, Assembly

Posted 21 March 2014 - 08:22 PM

space .. spacing .. the code is correct right ?...

You'll have to use some conditional statements as well as the loops. For example:

```if(row > 1 && col > 1)
print (" ");
else
print (col);
```

Warning: this is not the exact code, but should lead you in the right direction to print the rows between the first and last row.

• 0

### #100 PanjiPro

PanjiPro

CC Lurker

• New Member
• 6 posts
• Learning:Java, C++, C#, (Visual) Basic, JavaScript, Visual Basic .NET, VBScript, Others

Posted 21 March 2014 - 09:04 PM

You'll have to use some conditional statements as well as the loops. For example:

```if(row > 1 && col > 1)
print (" ");
else
print (col);
```

Warning: this is not the exact code, but should lead you in the right direction to print the rows between the first and last row.

can you help me in this one ?.. can you .. ?

show me all the codes . please ..

• 0

### #101 KJGino

KJGino

CC Devotee

• Senior Member
• 424 posts
• Location:Chicago
• Programming Language:C, Java, C++, PHP, (Visual) Basic, JavaScript, Visual Basic .NET, Transact-SQL
• Learning:Python, Assembly

Posted 21 March 2014 - 09:20 PM

can you help me in this one ?.. can you .. ?

show me all the codes . please ..

Sorry, but we won't do your homework for you here...but we will try help you learn what you don't know.

I suggest that you start by outlining exactly what it is that you need to do, for example:

```row will be the outer loop -- which will print the rows -- and will == 1 to 10
col will be the inner loop -- which will print the columns of the row -- and will == 1 to 10

1. print all the columns of the first row (col)
2. print only the first and last columns of all rows in between the first and last rows (use a conditional statement to only print (col * row) if it is the first or last column, else print a space)
3. print all the columns of the last row (col * row)
```

From this, you can create your psuedocode...then on to your actual code.

Hope this helps.

• 0

### #102 PanjiPro

PanjiPro

CC Lurker

• New Member
• 6 posts
• Learning:Java, C++, C#, (Visual) Basic, JavaScript, Visual Basic .NET, VBScript, Others

Posted 21 March 2014 - 09:22 PM

Sorry, but we won't do your homework for you here...but we will try help you learn what you don't know.

I suggest that you start by outlining exactly what it is that you need to do, for example:

```row will be the outer loop -- which will print the rows -- and will == 1 to 10
col will be the inner loop -- which will print the columns of the row -- and will == 1 to 10

1. print all the columns of the first row (col)
2. print only the first and last columns of all rows in between the first and last rows (use a conditional statement to only print (col * row) if it is the first or last column, else print a space)
3. print all the columns of the last row (col * row)
```

From this, you can create your psuedocode...then on to your actual code.

Hope this helps.

thank you so much ...

• 0

### #103 wishmaster

wishmaster

CC Lurker

• Just Joined
• 2 posts

Posted 20 April 2014 - 12:03 PM

Hello everyone!

This is my first post here,so excuse me if i write something wrong.

I was looking at this tpic,and i havent found question like mine.

Im absolute beginner in java,but i need to write a class,that will give me output like this:

*

***

*****

***

*

I have to use for loop,i know that i have to use nested for loops,for rows and columns. I just cant figure it out the thing with spaces,and how to turn it to count back.

Hope you guys understand what i want. Thank you all! Greetings and happy holidays!

• 0

### #104 lespauled

lespauled

• Expert Member
• 1,125 posts
• Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 21 April 2014 - 04:38 AM

The thing you did wrong was look through all 9 pages of this thread to see if your answer lies within, before posting.

• 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

### #105 wishmaster

wishmaster

CC Lurker

• Just Joined
• 2 posts

Posted 21 April 2014 - 09:19 AM

The thing you did wrong was look through all 9 pages of this thread to see if your answer lies within, before posting.

I did go through all the pages,and there is no problem like mine. If thats a forum to critise newcomers,the only wrong thing i did,was when i have registered here.

Tnx anyway for the help!

Edited by wishmaster, 21 April 2014 - 09:19 AM.

• 0

### #106 Ritwik I the programmer

Ritwik I the programmer

• 205 posts
• Programming Language:Java
• Learning:Java, C++, Python

Posted Today, 07:04 AM

Not the exact one perhaps, but there are a lot of arrangement problems in the preceding pages. It is always better if try to work out a problem yourself with a few hints than if you are handed down the solution.

As for your question, try doing it with two nested loops, one for the upper triangle including the middle line and another to print the bottom half of the diamond. For the upper triangle the number of spaces at the beginning of a line is equal to n - i, where i is the line number of thecurrent line and n the line number of the middle line.

• 0

1.Make it simple 2.Make it simple 3.Make it simple 4.make it simple 5. ............