# Need help with nested for loops to print the following number pattern

• September 4th, 2012, 09:49 PM
xdx
Need help with nested for loops to print the following number pattern
1
2, 1
1, 2, 3
4, 3, 2, 1
...............
.................
....................
...................... (upto 10)

notice the absence of comma at the end of the last integer
• September 4th, 2012, 10:19 PM
Zaphod_b
Re: Need help with nested for loops to print the following number pattern
Quote:

Originally Posted by xdx
...notice the absence of comma at the end of the last integer...

Well, here's the deal: Assuming this is the desired output of a program, every number will be printed because an instruction in the program prints it.

Furthermore...

Every comma will be printed because an instruction in the program prints it.

So...

If you don't want a commas at the end of the last integer on the lines, then don't put instructions in the program to print them.

If we could see your code, maybe we could understand why it prints stuff that you don't want (assuming that's the kind of help you would like).

Cheers!

Z
• September 5th, 2012, 06:05 AM
Mr.777
Re: Need help with nested for loops to print the following number pattern
In a loop, just create a check if it's 1 don't follow it with comma, else keep printing the number following comma.
Remember, if it's 1, if it's other than 1, i hope you can make the logic.
• September 5th, 2012, 02:09 PM
jps
Re: Need help with nested for loops to print the following number pattern
Quote:

Originally Posted by Mr.777
In a loop, just create a check if it's 1 don't follow it with comma, else keep printing the number following comma.
Remember, if it's 1, if it's other than 1, i hope you can make the logic.

I disagree.
Under that logic the lines that count up (ie line 3: 1,2,3) would have a comma at the end because they do not end with a 1
• September 6th, 2012, 05:29 AM
Mr.777
Re: Need help with nested for loops to print the following number pattern
Ops yeah it's first ascending then descending. Yeah you are right jps.
Yeah then that would become for getting the size if let's assume (i is dealing in the loop) i has the value which is almost gonna end up the loop after the iteration, don't put comma otherwise continue with the other statements.