Prev | ICM Language Reference Flow control | Next |
[ Loops | Conditions | Jumps ]
ICM contains a complete set of control statements to allow looping, jumping and conditional branching.Loops |
for <i_index> = <i_from> , <i_to> [, <i_increment> ] ... ... endfor
while( <logical_expression> ) ... ... endwhile
for i = 1, 9 print "ICM-shell proudly announces that i=" i endfor for i = 1, 4 print "ICM-shell proudly announces that i=" i for j = 1, 3 print "ICM-shell proudly announces that nesting is possible and j=" j endfor endfor read object "crn" for i = 1, Nof(a_/*) # Nof(a_/*) means 'the number of residues' print Label(a_/$i) endfor i = -2 while (i != 4) i = i+1 print i endwhile while(yes) print "endless loop, please wait 8-)" endwhileAny number of nested loops may be used.
Conditional branching |
if ( <logical_expression> ) <command>
if ( <logical_expression> ) then ... ... endif
if( <logical_expression> ) then ... else ... endifor
if ( <logical_expression> ) then ... elseif ( <logical_expression> ) then ... elseif ( <logical_expression> ) then ... else ... endifNote: end if or else if (instead of endif or elseif ) are not accepted by ICM-shell.
JohnnySaid = "The gloves didn't fit" if ( JohnnySaid == "The gloves didn't fit" ) print "You must acquit" # grade = "bad" if (grade == "excellent") then print "It's great!" elseif (grade == "good") then print "It's good!" elseif (grade == "bad") then print "It's not so bad!" # do not be harsh on your kids endif
Jumps |
<for-loop> or <while-loop> ... if ( <logical expression> ) break ... <end of loop>
<for-loop> or <while-loop> ... if ( <logical expression> ) continue ... <end of loop>
... if ( <logical expression> ) goto <label> ... ... <label>: ...
for i = 1, 6 print "currently i=", i, "and it will be increased at the next step" if (i == 3) then print "... but at this point we should stop it, sorry..." break endif endfor print "end of the loop demonstrating *break*, bye" for i = 1, 6 if (i == 3) then print "... let us skip over step 3 and continue looping" continue endif print "currently i=", i, "and it will be increased at the next step" endfor print "end of the loop demonstrating *continue*, bye" for i = 1, 5 if (i == 3) then print "... but at this point we decided to skip 3-rd step, sorry..." goto A endif print "currently i=", i, "and it will be increased at the next step" A: print " " endfor print "end of the loop demonstrating 'goto', bye"
Prev Advanced | Home Up | Next MolObjects |