1 Replies - 7799 Views - Last Post: 16 September 2009 - 03:08 AM Rate Topic: -----

#1 dreamachine8485  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-September 09

For Next Loop for Diamond Shape

Posted 15 September 2009 - 10:48 PM

Hello there, I am sorry to trouble you guys but I need help to solve this problem. I am new here and pls guide me through in programming.
I have done the coding to create a diamong shape using the for next loop but the output comes out differently:

 Module Diamond
			Sub Main()
				 Dim row, space, asterisk As Integer
				 Dim height=5 As Integer
				 Dim height2=4 As Integer
			
			 For row=1 To height
				 For space=1 To (height-row)
					  Console.Write( " ")
				 Next
				 
				 For asterisk=1 To (2*row-1)
					  Console.Write("*")
				 Next
				 Console.WriteLine()
			 Next


			 For row=1 To height2
				  Console.Write(" ")
				  For space=height2-row To space-1
						Console.Write("*")
				  Next

				  For asterisk=1 To (2*row-1)
						Console.Write("*")
				  Next
				  
				  Console.WriteLine()
			 Next
	  End Sub
End Module 


The output that I get is:
*
***
*****
*******
**********
*
***
*****
*******

Which part of my coding went wrong? Tq.

From,
Nadia.

Is This A Good Question/Topic? 0
  • +

Replies To: For Next Loop for Diamond Shape

#2 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: For Next Loop for Diamond Shape

Posted 16 September 2009 - 03:08 AM

The 4th For loop is counting upwards - 1, 2, 3, 4

You want it to count downwards: 4, 3, 2, 1

You can do that using Step:

For row = height2 to 1 Step -1

It will still have some mistakes, but it is the main problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1