Home

Collapsible if statements should be merged

Rule description

  • Collapsible if statements should be merged

 

Non-compliant Code Example

function string TestFunctionCall (string cnt)

string cnt1;

if cnt = "1" then
    if cnt1 = "2" then //Non compliant code
        messagebox('Success')

    end if
end if

return cnt

end function
function string TestFunctionCall (string cnt)

IF x > 1 THEN 
     IF x > 2 THEN //Non compliant code
	    IF x > 3 THEN //Non compliant code
		    IF x > 4 THEN //Non compliant code
			    IF x > 5 THEN //Non compliant code
				    cnt = "x > 5"
			    END IF;
            END IF;
        END IF;
     END IF;
 END IF;

return cnt

end function

Compliant Code Example

function string TestFunctionCall (string cnt)

string cnt1;

if cnt = "1" AND cnt1 = "2" then //Compliant code (Merged collapsible IF condition into one)
        messagebox('Success')
end if

return cnt

end function
function string TestFunctionCall (string cnt)

IF x > 1 AND x > 2 AND x > 3 AND x > 4 AND x > 5 THEN //Compliant code (Merged collapsible IF condition into one)
	cnt = "x > 5"
END IF;

return cnt

end function
function string TestFunctionCall2 (string cnt)

IF x > 1 AND x > 2 THEN //Compliant code
		cnt = "x > 2"
	END IF;
	IF x > 3 THEN 
		cnt = "x > 3"
        END IF;
	IF x > 4 THEN 
		cnt = "x > 4"
	END IF;
	IF x > 5 THEN 
		cnt = "x > 5"
	END IF;
 END IF;

return cnt

end function
Visual Expert 2020
 VEPBRULE53