Home

GOTO should not be used within loops

Rule description

  • GOTO should not be used within loops

 

Non-compliant Code Example

function int TestFunctionCall (int cnt)

DO WHILE cnt <= 15
    
    IF cnt < 0 THEN
        goto restart; //Non compliant code (GOTO statement is used within loop)
    END IF;
      
      cnt = cnt - 1
LOOP

messagebox('Test','testing... ')

restart: 
if isvalid(cnt) and not isnull( cnt ) then
	messagebox('Test','is valid found ')
end if

return cnt;

end function

Compliant Code Example

function cnt TestFunctionCall (int cnt)

DO UNTIL  (cnt <= 15 AND cnt >= 0)
      cnt = cnt - 1
LOOP 

messagebox('Test','testing... ')

if isvalid(cnt) and not isnull( cnt ) then
	messagebox('Test','is valid found ')
end if

return cnt;

end function
Visual Expert 2020
 VEPBRULE45