Home

CASE structures should not have too many WHEN clauses

Rule description

  • CASE structures should not have too many WHEN clauses

 

Non-compliant Code Example

private function string TestFunctionCall (int cnt)

string sle_message

CHOOSE CASE Real(cnt)

CASE is < 10
		sle_message = " < 10"
CASE 11 to 20
		sle_message = " 11 to 20"
CASE 21 to 30
		sle_message = " 21 to 30"
CASE 31 to 40
		sle_message = " 31 to 40"
CASE 41 to 50
		sle_message = " 41 to 50"
CASE 51 to 60
		sle_message = " 51 to 60"
CASE 61 to 70
		sle_message = " 61 to 70"
CASE 71 to 80
		sle_message = " 71 to 80"
CASE 81 to 90
		sle_message = " 81 to 90"
CASE 91 to 100
		sle_message = " 91 to 100"
CASE is > 200
		sle_message = " > 200"   //Non compliant code (Allowed less than 10 number of case statements)
CASE ELSE
		sle_message = "Cannot evaluate!"  
END CHOOSE

return ""

end function

Compliant Code Example

private function string TestFunctionCall (int cnt)

string sle_message

CHOOSE CASE Real(cnt)

CASE is < 10
		sle_message = " < 10"
CASE 11 to 20
		sle_message = " 11 to 20"
CASE 21 to 30
		sle_message = " 21 to 30"
CASE 31 to 40
		sle_message = " 31 to 40"
CASE 41 to 50
		sle_message = " 41 to 50"
CASE 51 to 60
		sle_message = " 51 to 60"
CASE 61 to 70
		sle_message = " 61 to 70"
CASE ELSE
        sle_message = " > 70"   //Compliant code (Case statements are below allowed limit of 10)
END CHOOSE

return ""

end function
Visual Expert 2020
 VEPBRULE48