# Expecting }, found 'else'

**URL:** <https://discourse.processing.org/t/expecting-found-else/19328>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 2, 2020, 8:19am UTC](https://discourse.processing.org/t/expecting-found-else/19328 "2020-04-02T08:19:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soolim](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@soolim](https://discourse.processing.org/u/soolim)\
**Post date:** [April 2, 2020, 8:19am UTC](https://discourse.processing.org/t/expecting-found-else/19328/1 "2020-04-02T08:19:22Z")

</div>

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.

```auto
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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 2, 2020, 8:40am UTC](https://discourse.processing.org/t/expecting-found-else/19328/2 "2020-04-02T08:40:36Z")

</div>

Hello,

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

[This](https://discourse.processing.org/t/help-processing-coding/19279) is your other related post.

There are lots of resources here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

You have many errors (underlined in red):

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d0fd12f77e40503862891dbd5be4dc195d306bc6.png)

You have variables that were not declared.  
Discussed here:

[![](https://img.youtube.com/vi/B-ycSR3ntik/hqdefault.jpg "4.1: Variables - Processing Tutorial") ](https://www.youtube.com/watch?v=B-ycSR3ntik)

You did not use random correctly:

> **[random() / Reference](https://processing.org/reference/random_.html)**
>
> Generates random numbers. Each time the random() function is called, it returns an unexpected value within the specified range. If only one parameter is passed to the function, it will return a…

`:)`

---

<div class="post-metadata">

**Author:** ![Helron](https://avatars.discourse-cdn.com/v4/letter/h/cab0a1/32.png) [@Helron](https://discourse.processing.org/u/Helron)\
**Post date:** [April 2, 2020, 8:54am UTC](https://discourse.processing.org/t/expecting-found-else/19328/3 "2020-04-02T08:54:33Z")

</div>

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 ^^

```auto
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);}
}
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 2, 2020, 11:42am UTC](https://discourse.processing.org/t/expecting-found-else/19328/4 "2020-04-02T11:42:06Z")

</div>

**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**

```auto

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);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 2, 2020, 1:25pm UTC](https://discourse.processing.org/t/expecting-found-else/19328/5 "2020-04-02T13:25:16Z")

</div>

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](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 \>

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/042168eb35f8a04a9a0fe1a3fb2937c0878e835f.png)

Have fun programming!

`:)`
