Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
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!

VB
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

        Console.ReadLine()

    End Sub

End Module


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

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

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

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

Pattern 5
*
***
*****
*******
*********
*******
*****
***
*
Posted
Updated 6-Oct-13 14:30pm
v4
Comments
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?

1 solution

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
C#
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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