The if statement executes a sequence of statements. The sequence depends on the value of one or more conditions. The syntax follows.
if condition then
{ sequential_statement }
{ elseif condition then
{ sequential_statement } }
[ else
{ sequential_statement } ]
end if;
Each condition must be a Boolean expression. Each branch of an if statement can contain one or more sequential_statements.
An if statement evaluates each condition in order. The first (and only the first) TRUE condition causes the execution of its branch's statements. The remainder of the if statement is skipped.
If none of the conditions are TRUE, and the else clause is present, those statements are executed.
If none of the conditions are TRUE, and no else is present, none of the statements is executed.
The example below shows an if statement and its corresponding circuit is shown in the figure following the example.
signal A, B, C, P1, P2, Z: BIT;
if (P1 = '1') then
Z <= A;
elseif (P2 = '0') then
Z <= B;
else
Z <= C;
end if;
Figure 6.2 Circuit for the if Statement |
Some forms of the if statement can be used like the wait statement, to test for signal edges and, therefore, imply synchronous logic. When you use the if statement like the wait statement, Foundation Express infers registers or latches, as described in the Register and Three-State Inference chapter.