GOTO Instruction |
GOTO gotolabel
You can accomplish most program control with instructions like IF, ELSE, WHILE, UNTIL, BREAK and NEXT. However, there are situations when it is simpler to jump directly to a specific instruction. This is the purpose of GOTO. You can also use BRANCH as a synonym for GOTO.
Parameters
gotolabel |
The label indicating the point in the program where you want to continue execution. RATS permits forward and backward branching. This can be any combination of up to sixteen characters.
In the location to which you want to jump, the target label must be prefixed with a colon (:). Put at least one blank between the end of the label and the next instruction. |
Notes
The GOTO instruction and the associated gotolabel must both be part of the same Compiled Section. The GOTO instruction can be "nested" deeper than the gotolabel, but you cannot jump into a compiled block from outside that block. For example, you can jump out of a nested loop, but you cannot jump into a nested loop. The following is illegal:
goto 100
dofor xmat = amat bmat cmat
:100 matrix xmat=inv(xmat)
end dofor
Example
This is part of the ARMAGIBBS.RPF program file. This checks whether draws for two parameter are outside the permissible range. If they are, it skips down to the "reject" label.
*
* Reject if AR or MA coefficient is out of range.
*
if abs(btest(2))>=1.0.or.abs(btest(3))>=1.0
goto reject
*
* Evaluate the likelihood and do the Metropolis test.
*
boxjenk(diffs=1,constant,ar=1,ma=1,maxl,initial=btest,method=evaluate) logppi
compute logptest=%logl
compute alpha =exp(logptest-logplast-logqtest+logqlast)
if alpha>1.0.or.%uniform(0.0,1.0)<alpha {
compute bdraw=btest,logplast=logptest,$
logqlast=logqtest,accept=accept+1
}
:reject
infobox(current=draw) %strval(100.0*accept/(draw+nburn+1),"##.#")
Copyright © 2025 Thomas A. Doan