Jump to content





Recent Status Updates

  • Photo
      16 Apr
    Kadence

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

    Show comments (6)
  • Photo
      10 Apr
    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. :)

View All Updates
Photo
- - - - -

Nested For Loop [EXAMPLES!]

nested loop for loop loop

101 replies to this topic

#97 KJGino

KJGino

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 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 ..

 

how about this ..

 

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
  • Pip
  • 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.

owh.. none .. please help me .. can you ?..


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
  • PipPipPipPipPipPip
  • 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
  • Pip
  • 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
  • PipPipPipPipPipPip
  • 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
  • Pip
  • 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





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