Home

GOTO should not be used to jump backwards

Rule description

  • GOTO should not be used to jump backwards

 

Non-compliant Code Example

function integer calculateSteps(integer step)

integer totalSteps = 0

restart: //Non compliant code (goto jump backwards)
	
	totalSteps = totalSteps + step
	step = step - 1

	if step > 0 then
		goto restart
	end if


return totalSteps

end function

Compliant Code Example

function integer calculateSteps(integer step)

integer totalSteps = 0

do 
	totalSteps = totalSteps + step
	step = step - 1

loop while(step > 0) //Compliant code

return totalSteps

end function
Visual Expert 2020
 VEPBRULE31