Nested conditional branching statements:
caseifwhile and for loopsare difficult to understand because you can easily confuse the conditions of an inner construct as belonging to an outer statement. Therefore too deeply nested conditional branching statements should be avoided.
You should structure your code to avoid the need for nested conditional branching statements. But, if you cannot, consider moving the inner conditional branching statements to dedicated functions.
Also, nesting too many branching statements could lead to issues with timing closure.
1
if a = 5 then
z <= a;
if b = 6 then
y <= b;
if c = 7 then -- Noncompliant: Two nesting levels
x <= c;
end if;
else
y <= 0;
end if;
end if;
With a custom value of maximum number of authorized nested levels: 0 (no nesting allowed)
if a = 5 then
z <= a;
if b = 6 then -- Noncompliant: Nested "if" statement
y <= b;
else
y <= 0;
end if;
end if;
With a custom value of maximum number of authorized nested levels: 0 (no nesting allowed)
if a = 5 then
z <= a;
case b is -- Noncompliant: "case" statement nested in "if" statement
when '0' => y <= b;
when '1' => y <= 0;
when others => y <= 0;
end case;
end if;
1
if a = 5 then
z <= a;
if b = 6 then
y <= b;
else
y <= 0;
end if;
end if;