Why is "end if" missing at the end of an if-else sequence?

Viewed 72

The error is

teclat.vhdl:57:12: 'if' is expected instead of 'process'

The end if is where it is supposed to be. I don't understand why it doesn't compile like it's missing an end if always.

architecture v1 of teclat is
begin
    process(Buttons, COL, ROW) begin

    if (Buttons(1) = '1') then
        COL <= "100";
        ROW <= "100";
    else if (Buttons(2) = '1') then
        COL <= "010";
        ROW <= "100";
    else if (Buttons(3) = '1') then
        COL <= "001";
        ROW <= "100";
    else 
        ROW <= "111";
    end if;

    end process;
end v1;
1 Answers

There is one end if where it is supposed to be, but you are missing the ones for the remaining if statements you opened.

Your code is currently processed as

if (Buttons(1) = '1') then
    COL <= "100";
    ROW <= "100";
else
    if (Buttons(2) = '1') then
        COL <= "010";
        ROW <= "100";
    else
        if (Buttons(3) = '1') then
            COL <= "001";
            ROW <= "100";
        else
            ROW <= "111";
        end if;
    end if; -- missing
end if; -- missing

Alternatively, use elsif to avoid opening so many if statements. Now you have only a single if statement and need only one end if.

if (Buttons(1) = '1') then
    COL <= "100";
    ROW <= "100";
elsif (Buttons(2) = '1') then
    COL <= "010";
    ROW <= "100";
elsif (Buttons(3) = '1') then
    COL <= "001";
    ROW <= "100";
else
    ROW <= "111";
end if;
Related