ICM Manual

[ Loops | Conditions | Jumps ]

ICM contains a complete set of control statements to allow looping, jumping and conditional branching.

Loops

Two types of loops are allowed, namely for-loop and while-loop.
For-loop
for  <i_index> = <i_from> ,  <i_to> [, <i_increment> ] 
  ... 
  ... 
 endfor

While-loop
while( <logical_expression> ) 
  ... 
  ... 
 endwhile

Examples:
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-)" 
 endwhile
Any number of nested loops may be used.

Conditional branching

Several types of conditional statements are allowed in the ICM-shell.
if
if ( <logical_expression> ) <command>

if-then-endif
if ( <logical_expression> ) then 
    ... 
    ... 
 endif

if-then-elseif-..else-endif
if( <logical_expression> ) then 
     ... 
 else 
     ... 
 endif
or
if ( <logical_expression> ) then 
   ... 
 elseif ( <logical_expression> ) then 
   ... 
 elseif ( <logical_expression> ) then 
   ... 
 else 
   ... 
 endif
Note: end if or else if (instead of endif or elseif ) are not accepted by ICM-shell.
Examples:
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

Three types of jump controls are possible, namely commands break, continue and goto. break interrupts the loop, continue skips commands until the nearest endfor or endwhile and continues looping, and goto jumps to any point below.
break
<for-loop> or <while-loop> 
     ... 
     if ( <logical expression> ) break 
     ... 
 <end of loop>

continue
<for-loop> or <while-loop> 
     ... 
     if ( <logical expression> ) continue 
     ... 
 <end of loop>

goto
... 
 if ( <logical expression> ) goto <label> 
 ... 
 ... 
 <label>: 
 ...

Examples:
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"

Note: go to (instead of goto) is not accepted by the ICM-shell. Any combination of alphanumeric characters beginning with a letter (upper or lower case) may serve as a label. Also keep in mind that goto can jump only forward; the backward goto is not allowed.