14,695,503 members
See more:
I don't want the answer to the code - I want to know why did my Pattern 2 work? I would like to know the why behind it! Please Help!

I have searched all over google, referred to my text book and my class notes and I am stuck! I feel like I am missing something small but that small thing is messing me up. I need to code the below patterns using For...Next statements. Here is the code I have so far, part of this is that I figured out one of the 5 patterns but I don't know why it worked! So frustrated! Please help!

```Module Module1

Sub Main()
Console.WriteLine("Pattern 1")

Dim count As Integer
Dim count2 As Integer

For count = 0 To 10
For count2 = 1 To 10
Console.WriteLine("*")
Next
Next

Console.WriteLine()

Console.WriteLine("Pattern 2")

For count = 0 To 10
For count2 = 1 To 10 - count
Console.Write("*")
Next
Console.WriteLine()

Next

End Sub

End Module```

Pattern 1
*
**
***
****
*****
******
*******
********
*********
**********

Pattern 2
**********
*********
********
*******
******
*****
****
***
**
*

Pattern 3
**********
*********
********
*******
******
*****
****
***
**
*

Pattern 4
*
**
***
****
*****
******
*******
********
*********
**********

Pattern 5
*
***
*****
*******
*********
*******
*****
***
*
Posted
Updated 6-Oct-13 15:30pm
v4
Ron Beyer 6-Oct-13 18:16pm

You say it didn't work, but you never said what the output is supposed to look like, so how can we know what you did wrong?

## Solution 1

As this looks like a home assignment, no code, just general directions. An exercise can only be useful for you if you do it by yourself.

You use the immediate constant 10 four times. This is unsupportable. If you cannot or don't get a value from some data (user input, configuration file, resource, etc.), you should declare it as a constant
`const uint maximumLineLength = 10;`

You have only 3 difference patterns, not 5: #1, #2 and #5. It is apparent that two of then needs only two, nested, loops, and outer loop in #5 could be repeated twice in different direction, but I would advise you to think about the solution where you use the outer loop from 1 to 20 (`2 * maximumLineLength`), but only one.

If you don't understand why something doesn't work as planned, use the debugger. You should develop the basic skills of fixing code by yourself.

—SA

Top Experts
Last 24hrsThis month
 OriginalGriff 250 RickZeeland 120 Rick York 100 Richard Deeming 100 Sandeep Mewara 100
 OriginalGriff 6,079 Richard Deeming 3,165 Richard MacCutchan 2,824 CPallini 2,012 Patrice T 1,650

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900