Using INCLAN control statements: Difference between revisions
(Created page with 'INCLAN provides a full set of control statements to direct the program flow. These are used mainly in macros, i. e. in collections of INCLAN statements that form new commands whi…') |
No edit summary |
||
Line 1: | Line 1: | ||
INCLAN provides a full set of control statements to direct the program flow. These are used mainly in macros, i. e. in collections of INCLAN statements that form new commands which can be used in the same way as basic commands. Since control statements are not used interactively, the program prompt (“cyana>”) will no longer be shown. | INCLAN provides a full set of control statements to direct the program flow. These are used mainly in macros, i. e. in collections of INCLAN statements that form new commands which can be used in the same way as basic commands. Since control statements are not used interactively, the program prompt (“cyana>”) will no longer be shown. | ||
Commands can be executed conditionally by virtue of the “if” statement which has the same form as in Fortran: | Commands can be executed conditionally by virtue of the “if” statement which has the same form as in Fortran: | ||
if (i.gt.20) print "i is larger than 20." | if (i.gt.20) print "i is larger than 20." |
Revision as of 17:20, 11 August 2009
INCLAN provides a full set of control statements to direct the program flow. These are used mainly in macros, i. e. in collections of INCLAN statements that form new commands which can be used in the same way as basic commands. Since control statements are not used interactively, the program prompt (“cyana>”) will no longer be shown.
Commands can be executed conditionally by virtue of the “if” statement which has the same form as in Fortran: if (i.gt.20) print "i is larger than 20." if (i.lt.0) then
print "i is negative."
else if (i.lt.10 .and. mod(i,2).eq.0) then
print "i is less than 10 and even."
else
print "i is none of the above."
end if Alternatively, comparison and logical operators can also be given in the form of the C programming language: if (i>20) print "i is larger than 20." if (i<0) then
print "i is negative."
else if (i<10 && mod(i,2)==0) then
print "i is less than 10 and even."
else
print "i is none of the above."
end if Note, however, that expressions are always evaluated according to the rules of Fortran-77. Repeated execution of commands is achieved by forming loops with the “do” statement. Loops executed a predefined number of times have an integer loop variable: do i 1 20
print "i = $i"
end do Here, the loop variable, i, runs from 1 to 20 in steps of 1. A loop that is executed until a termination condition is met can be constructed as follows: do
... if (x.gt.100.0 .or. finished) break ...
end do The “break” statement exits from a loop. Unconditional jumps are possible with the “go to” statement:
do i 1 n ... if (err) go to cleanup ... end do ...
cleanup: print "Error in the loop."
...
The “go to” statement transfers the program flow to the position indicated by the label (“cleanup”).