Expecting }, found 'else'

Hello.
An error occurred during processing coding. I don’t know what the problem is.
In points (a,b), a wants to get a +d(random)

The error is the same as ’ expecting }, found ‘else’ '.
If you’re good at processing, please give me some advice.

void setup() {
  int a = 0;
  int b = 10;
  int d = random(8, 16, 20);
  size(400, 400);
}
void draw() {
  background(190, 255, 255);
  strokeWeight(30);
  stroke(0, 0, 0, 50);
  point(a, b); 
  
for (i = a; i <= width; ++i) {
  
  if (i < 400);
    e = true;
  } else {
    e = false;
  }
  if (e == true) {
    point(i, b);
  }
  if (e == false) {
    point(i, j);
  }
}
2 Likes

Hello,

Please format your code as a courtesy to everyone:
https://discourse.processing.org/faq#format-your-code

This is your other related post.

There are lots of resources here:

You have many errors (underlined in red):

You have variables that were not declared.
Discussed here:

You did not use random correctly:

:)

2 Likes

Hello,
I don’t know if it s helpfull but if you don’t find your ifferent mistaskes by your own… here a code that do not resolve the random problem.

Have a good day ^^

int a = 0;
int b = 10;
int i=1;
int j;
boolean e;

void setup() {
  int d = random(16, 20);
  size(400, 400);
}


void draw() {
  background(190, 255, 255);
  strokeWeight(30);
  stroke(0, 0, 0, 50);
  point(a, b);

  for (i = a; i <= width; ++i) {

            if (i < 400){ e = true; } else {e = false;};
            if (e == true) { point(i, b);};
            if (e == false) { point(i, j);}
}
}
2 Likes

Remark

You declared variables a and b in setup and tried to use them in
draw().
That doesn’t work.

declare them before setup() so they are known everywhere. This is called Variable Scope.

Remark

You had this:

if (i < 400);

The semicolon ENDS the if-clause. Bad.

Remark

Also you had a closing } bracket, but no opening bracket, so processing assumed you were closing the for loop

Remark

You had point(i, j); but there is no j.

Remark

You if was for <400 but 400 is also your maximum screen, so e was always true.

Chrisir

Full code



int a = 0;
int b = 10;
float  d = random(8, 20);

boolean e; 

void setup() {
  size(400, 400);
}
void draw() {
  background(190, 255, 255);

  strokeWeight(30);

  stroke(0, 0, 0, 50);
  point(a, b);

  for (int i = a; i <= width; i++) {

    if (i < 200) {
      e = true;
    } else {
      e = false;
    }

    if (e == true) {
      point(i, b);
    }
    if (e == false) {
      point(i, 20);
    }
  }
}
3 Likes

Hello again @soolim,

Adding a few things below… the last post was middle of the night for me.

Variable Scope:
https://processing.org/examples/variablescope.html

If you hover over a red error or orange warning it will show the error in the bar below code (above console).

You can set preferences in the Processing PDE (PDE what is that?) for errors and warnings and lots of other stuff:
file > preferences >

Have fun programming!

:)

2 Likes