How to use for loop in vhdl code?

Answer:
A loop statement is used to iterate through a set of sequential statements. The syntax of a loop statement is

[ loop-label : ] iteration-scheme loop
sequential-statements
end loop [ loop-label ] ;

There are three types of iteration schemes. The first is the for iteration scheme that has the form

for identifier in range

An example of this iteration scheme is

FACTORIAL := 1;
for NUMBER in 2 to N loop
FACTORIAL := FACTORIAL * NUMBER;
end loop;

The body of the for loop is executed (N-1) times, with the loop identifier, NUMBER, being incremented by I at the
end of each iteration. The object NUMBER is implicitly declared within the for loop to belong to the integer type
whose values are in the range 2 to N. No explicit declaration for the loop identifier is, therefore, necessary. The
loop identifier, also, cannot be assigned any value inside the for loop. If another variable with the same name exists
outside the for loop, these two variables are treated separately and the variable used inside the for loop refers to the
34loop identifier.
The range in a for loop can also be a range of an enumeration type such as

type HEXA is ('0', '1', '2', '3', '4', ' 5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'):
. . .
for NUM in HEXA'('9') downto HEXA'('0') loop
-- NUM will take values in type HEXA from '9' through '0'.
. . .
end loop;

for CHAR in HEXA loop
-- CHAR will take all values in type HEXA from '0' through 'F'.
. . .
end loop;

Notice that it is necessary to qualify the values being used for NUM [e.g., HEXA'('9')] since the literals '0' through
'9' are overloaded, once being defined in type HEXA and the second time being defined in the predefined type
CHARACTER
First answer by ID3418420770. Last edit by ID3418420770. Question popularity: 1 [recommend question].