# Issue with expecting }, found 'else'

**URL:** <https://discourse.processing.org/t/issue-with-expecting-found-else/26377>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [December 19, 2020, 10:10am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377 "2020-12-19T10:10:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yevsym](https://avatars.discourse-cdn.com/v4/letter/y/bc8723/32.png) [@yevsym](https://discourse.processing.org/u/yevsym)\
**Post date:** [December 19, 2020, 10:10am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/1 "2020-12-19T10:10:51Z")

</div>

I wrote this code, but Processing keeps telling me about the “expecting }, found ‘else’” error. I checked my code many times, but I just stick at missing out the mistake. Please help out, if you spot it.

void draw()  
{  
stroke(255, 255, 255);  
strokeWeight(2);  
point(random(width), random (height));

noStroke();

if ((frameCount % 50) \< 25);  
{  
fill(255, 255, 0);  
}  
else  
{  
fill(215, 215, 0);  
}

triangle(width/2, 0,  
width/2 - 30, 60,  
width/2 + 30, 60);

triangle(width/2 - 30, 20,  
width/2 + 30, 20,  
width/2, 80);

noStroke();  
fill(255, 255, 255);  
rect(0, 0.9 \* height, width, 0.1 \* height);  
}

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 19, 2020, 10:15am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/2 "2020-12-19T10:15:47Z")

</div>

> [@yevsym](#):
>
> void draw()  
> {  
> stroke(255, 255, 255);  
> strokeWeight(2);  
> point(random(width), random (height));
> 
> noStroke();
> 
> if ((frameCount % 50) \< 25);  
> {  
> fill(255, 255, 0);  
> }  
> else  
> {  
> fill(215, 215, 0);  
> }
> 
> triangle(width/2, 0,  
> width/2 - 30, 60,  
> width/2 + 30, 60);
> 
> triangle(width/2 - 30, 20,  
> width/2 + 30, 20,  
> width/2, 80);
> 
> noStroke();  
> fill(255, 255, 255);  
> rect(0, 0.9 \* height, width, 0.1 \* height);  
> }

I found the issue. in the next reply ill point it out

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 19, 2020, 10:16am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/3 "2020-12-19T10:16:22Z")

</div>

> [@yevsym](#):
>
> if ((frameCount % 50) \< 25);

you used “;” . You should have used “{” so it works now.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 19, 2020, 10:21am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/4 "2020-12-19T10:21:16Z")

</div>

the `if( <boolean> ) <function> ;`  
it is the same as:

```auto
if( <boolean> ) {
   <function>;
}

```

and is used for this

```auto
void draw() {
  if(mouseX > width/2) background(255); else background(0);
}

```

however there can only be one function used in the `if();` statement

---

<div class="post-metadata">

**Author:** ![yevsym](https://avatars.discourse-cdn.com/v4/letter/y/bc8723/32.png) [@yevsym](https://discourse.processing.org/u/yevsym)\
**Post date:** [December 19, 2020, 10:22am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/5 "2020-12-19T10:22:52Z")

</div>

I spent hours looking for the mistake that you pointed out right away. It worked. Thank you so much.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 19, 2020, 10:23am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/6 "2020-12-19T10:23:57Z")

</div>

It’s just that I fell in love with the `if( <boolean> ) <function> ; ` It’s insanely useful for shortening the code

---

<div class="post-metadata">

**Author:** ![yevsym](https://avatars.discourse-cdn.com/v4/letter/y/bc8723/32.png) [@yevsym](https://discourse.processing.org/u/yevsym)\
**Post date:** [December 19, 2020, 10:25am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/7 "2020-12-19T10:25:12Z")

</div>

Will definitely try that out.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 19, 2020, 10:29am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/8 "2020-12-19T10:29:07Z")

</div>

here is a program I just wrote that shows it’s usefulness!

```auto
void draw() {
  if (mouseX < width/2 && mouseY < height/2) background(255, 0, 0); 
  else if (mouseX > width/2 && mouseY < height/2) background(0, 0, 255); 
  else if (mouseX < width/2 && mouseY > height/2) background(0, 255, 0); 
  else if (mouseX > width/2 && mouseY > height/2) background(255, 255, 0);
}

```

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 19, 2020, 10:33am UTC](https://discourse.processing.org/t/issue-with-expecting-found-else/26377/9 "2020-12-19T10:33:23Z")

</div>

here is a comparison! If mode == 1 it uses the old way, if mode == 0 it uses the shorter way

```auto
int mode = 1;
void draw() {
  if (mode == 0) {
    
    if (mouseX < width/2 && mouseY < height/2) background(255, 0, 0); 
    else if (mouseX > width/2 && mouseY < height/2) background(0, 0, 255); 
    else if (mouseX < width/2 && mouseY > height/2) background(0, 255, 0); 
    else if (mouseX > width/2 && mouseY > height/2) background(255, 255, 0);
    
  } else if (mode == 1) {
    
    if (mouseX < width/2 && mouseY < height/2) {
      background(255, 0, 0);
    } else if (mouseX > width/2 && mouseY < height/2) {
      background(0, 0, 255);
    } else if (mouseX < width/2 && mouseY > height/2) {
      background(0, 255, 0);
    } else if (mouseX > width/2 && mouseY > height/2) {
      background(255, 255, 0);
    }
    
  }
}

```
