В вашем выражении GOTO реализовано два типа потока управления:
Тип 1: разрыв цикла
Оператор GOTO используется для выхода из цикла DO:
DO acc0 = 1,intA+1
! some code
IF (cons<0.0) GOTO 102
! some more code
END DO
102 continue
Как вы заметили, если cons < 0.0
, оператор GOTO сообщает о перемещении на метку 102, которая находится за пределами цикла DO. В Matlab есть не что иное, как простой break
в цикле for:
for acc0=1:intA+1
% some matlab code
if (cons < 0.0)
break
end
% some more matlab code
end
Тип 2: создание цикла
Хотя цикл явно не написан, следующий код создает что-то, что можно перевести как цикл while:
! This is the start of the loop
102 continue
! This is the condition to exit the loop <<==
IF (askip<2) GO TO 109
! stuff
! This is a condition to restart the loop <<==
IF (vtemp>vmax) THEN
vmax = vtemp
amax_G = acc
GOTO 102
ENDIF
! stuff
! This is another condition to restart the loop <<==
IF (cons<0.0) GO TO 102
! stuff
! This is the end of the loop, asked to restart it <<==
GOTO 102
! This is outside of the loop
109 CONTINUE
В конце концов, вы переводите это как:
while (askip >=2)
% stuff
if (vtemp > vmax)
vmax = vtemp
amax_G = acc
continue
end
% stuff
if (cons < 0.0)
continue
end
% stuff
end