Loops in Managed COBOL
*> Pre-test loops:
declare c1 as binary-long.
perform until c >= 10
add 1 to c
end-perform
perform varying c as binary-long from 2 by 2 until c > 10
display c2
end-perform
*>Post-test loops:
declare c3 as binary-long.
perform with test after until c3 >= 10
add 1 to c3
end-perform
*> Array or collection looping
01 names string occurs any.
set content of names to ("Rod" "Jane" "Fred")
perform varying s as string through names
display s
end-perform
*> Breaking out of loops:
01 i1 binary-long value 0.
perform until exit
if i1 = 5
exit perform
end-if
add 1 to i1
end-perform
*> Continue to next iteration:
declare i2 binary-long value 0
perform varying i2 from 0 by 1 until i2 >= 5
if i2 < 4
exit perform cycle
end-if
display i2 *>Only prints 4
end-perform