title: Verilog: ERROR:HDLCompiler:806 - Line 117: Syntax error near "else"
body: <p>I'm tring to use fpga board to display graphical objects on screen via vga. In the code below, "flag" is only 1 bit. What I want to achieve is that when "flag" is 1, I make certain region one color; when "flag" is 0, it display another color. Verilog ISE keeps telling me that I have an error near the "else" statement in the code below(the "else" in the middle). Can anyone please tell me why? </p>
  
  <pre><code>        if (vc &gt;= (groundTop) &amp;&amp; vc &lt; (groundBottom))
              begin
                  red = 3'b111;
                  green = 3'b111;
                  blue = 2'b11;
              end
          // player level
          else if (vc &gt;= (groundTop-playerSize) &amp;&amp; vc &lt; groundTop)
              begin
  
                  if (flag==1)
                      begin
                          if (hc &gt;= (hbp+p1nbr*playerMove-playerMove*p1nbl) &amp;&amp; hc &lt; (hbp+playerSize+p1nbr*playerMove-playerMove*p1nbl))
                              begin
                                  red = 0;
                                  green = 0;
                                  blue = 0;
                              end
                          else
                              begin
                                  red = 3'b000;
                                  green = 3'b111;
                                  blue = 2'b11;
                              end
                      end
  
                  else
                      begin
                          else if (hc &gt;= (hbp+p1nbr*playerMove-playerMove*p1nbl) &amp;&amp; hc &lt; (hbp+playerSize+p1nbr*playerMove-playerMove*p1nbl))
                              begin
                                  red = 3'b111;
                                  green = 3'b111;
                                  blue = 2'b00;
                              end
                          else
                              begin
                                  red = 3'b000;
                                  green = 3'b111;
                                  blue = 2'b11;
                              end
                      end
              end
          //sky
          else 
              begin
                  red = 3'b000;
                  green = 3'b111;
                  blue = 2'b11;
              end
  </code></pre>
  
  <p>and here's how the error looks like.</p>
  
  <pre><code>ERROR:HDLCompiler:806 - "U:/public/work/ECEG_240/NERP_demo/vga640x480.v" Line 117: Syntax error near "else".
  ERROR:ProjectMgmt - 1 error(s) found while parsing design hierarchy.
  </code></pre>