Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scope problems with nested java loops

I'm learning processing (for those who don't know its a java-based language geared towards visual arts), and I've come across a strange problem with nested for loops. This is a simple program that (should) generate a random number of points, and connect them all.

size(1280, 1050);
background(227, 199, 147);
smooth();
stroke(255);
strokeWeight(2);

int points = int(random(30)) + 2;
int[][] Points  = new int[points][2];

for (int i = 0; i < points; i++)
 {
       Points[i][0] = int(random(1280));
   Points[i][1] = int(random(1050));
 }

for (int i = 0; i + 1 < points; i++)
{
  for (int L = i+1; L < points; L++);
  {
    line(Points[i][0], Points[i][1], Points[L][0], Points[L][1]);
  }
}

When I run this I get an error saying 'cannot find anything named L', which seems insane to me. Any ideas?

like image 870
shaftoes Avatar asked Dec 30 '25 16:12

shaftoes


1 Answers

You have a semicolon after the nested loop. This makes a syntactically correct empty loop, followed by a block that references an undeclared variable L.

As a side note, it is typical to name loop variables with lowercase letters, typically starting in i, j, k, m, and and so on. Lowercase l is often skipped due to its similarity to uppercase I.

like image 192
Sergey Kalinichenko Avatar answered Jan 02 '26 09:01

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!