Hi everyone
I am trying to code a program using loops that prints triangles.
for instance:
*
**
***
****
*****
then the other way
*****
****
***
**
*
My problem is I am using For---Next, but I am not sure how to start my counter.
I had for example

for i=1 to 1< 5 ( which is my counter)
  for j=1 to j< i
  next
next

I am trying to get it where the outer loop print the lines and the innner loop print the number of stars on each line separately.

any information on how I can do this will be much appeciated
thanks
computer_mom :confused:

I'm still slightly confused... a for loop in and of itself is a counter, but umn, the error is in your syntanx, it should look something more like:

for I = 1 to 5
     for J = 1 to I
          ' /* Do Stuff Here For Your Printing  */
     next J
next  I

If you want to maintain the indents when you post code, you can stick them in [ CODE ] [/ CODE ] Tags (with no spaces).

hi and thanks for the reply.
I figured out the first two triangles, now I have a third one that goes this way :*******


it's sorta out of line but that is the idea. I am thinking in order to do this I may have to add an if....else statement.
my logic is this
for i= 1 to 5
if i < something, then writeline("") to accomodate for the spaces. But I am unsure how to set this up.
any information or help will be appreciated
computer_mom

I'm still slightly confused... a for loop in and of itself is a counter, but umn, the error is in your syntanx, it should look something more like:

for I = 1 to 5
     for J = 1 to I
          ' /* Do Stuff Here For Your Printing  */
     next J
next  I

If you want to maintain the indents when you post code, you can stick them in [ CODE ] [/ CODE ] Tags (with no spaces).

Hi and thanks for the help
I figured it our for the two triangles, now I am needing a third.
that's right angles, in the opposite direction of the first two.

along with the
For i = 1 to 5, im thinking I need to add an if...next statement like
if i < a number to then print writeline("") to accomodate for the spaces..
any help or information will be much appreciated.
thanks
computer_mom

This article has been dead for over six months. Start a new discussion instead.