Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Drawing triangle by using for loops.

1. ## Drawing triangle by using for loops.

Hi all,

A few days ago I solved a problem in which I had create the figure shown below:

Screenshot4.PNGScreenshot4.PNG

```import java.awt.Graphics;
import java.applet.Applet;

public class driehoek extends Applet {

public void paint(Graphics g) {
int x, y;
for(y=0; y<10; y++)
for(x=0; x<y; x++)
g.drawRect(20*x, 20*y, 10, 10);
}
}```

However, because I have some difficulty understanding for loops and recursion I tried to create the figure shown below:

Screenshot5.png

and this is my code:

```
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class gekkeDriehoek extends Applet {

public void paint(Graphics g)
{
int x, y;

for(y=0; y<10; y++)
{
for(x = 9; x<y; x--)
{
g.drawRect(x*20, y*20, 10, 10);
}
}

}
}```

This code, however, returns a blank screen.
Does any of you see what my error is?

2. ## Re: Drawing triangle by using for loops.

Does any of you see what my error is?
Look at the second for loop. When is the continue clause ever true?