Critical

IF ... ELSEIF constructs should end with ELSE clauses

Description

    This rule states that IF...ELSEIF constructs should always end with an ELSE clause. This means that any IF...ELSEIF construct should have an ELSE clause at the end, which will be executed if none of the other conditions in the IF...ELSEIF construct are met. This ensures that all possible conditions are accounted for and that no unintended behavior occurs.

Key Benefits

  • Simplicity : IF ... ELSEIF constructs allow for simple and straightforward coding.
  • Flexibility : IF ... ELSEIF constructs provide flexibility in coding decisions, allowing for multiple options.
  • Readability : IF ... ELSEIF constructs make code easier to read and understand.
  • Efficiency : IF ... ELSEIF constructs should end with ELSE clauses to ensure efficient execution.

 

Non-compliant Code Example

function string TestFunctionCall (string cnt)

if cnt = 1 then
	messagebox('cnt = 1')
elseif cnt = 2 then 
	messagebox('cnt = 2')
end if //Non compliant code (ELSE clause is missing)

return cnt

end function

Compliant Code Example

function string TestFunctionCall (string cnt)

if cnt = 1 then
	messagebox('cnt = 1')
elseif cnt = 2 then 
	messagebox('cnt = 2')
else //Compliant code
    messagebox('cnt > 2')
end if 

return cnt

end function
Visual Expert 2023
 VEPBRULE63