Contents - Index

GOTO Statement and Statement Labels


GoTo statements can only be used in Functions and Procedures.  EES will normally process the assignment statements in a function or procedure in the order they appear starting with the first statement.  However, the flow control can be altered using GoTo statements.  The format of a GoTo statement is simply 


 GoTo #


where # is a statement label number that must be an integer number between 1 and 29999.  Statement labels precede an assignment statement separated with a colon (:).  The GoTo statement must be used with If Then Else or Repeat-Until statements to be useful.  The following function illustrates the use of GoTo and If Then Else statements in the calculation of the factorial of a value supplied as the argument.


Function factorial2(N)



10: i:=i+1


       If (i<N) Then Goto 10



Y= factorial2(5)   { Y will be set to 120 when this statement executes} 


Note that this function was name Factorial2 because there is a built-in function named Factorial that provides the same function.



Use of GoTo statements makes code more difficult to follow.  It is best to limit their use.  An alternative to the GoTo statement is the Return statement, which when encountered effectively results in a GoTo to the end of the Function or Procedure.