ICM Manual v.3.8
by Ruben Abagyan,Eugene Raush and Max Totrov
Copyright © 2018, Molsoft LLC
Apr 25 2018

Contents
 
Introduction
Reference Guide
 ICM options
 Editing
 Graph.Controls
 Alignment Editor
 Constants
 Subsets
 Molecules
 Selections
 Fingerprints
 Regexp
 Cgi programming with icm
 Xml drugbank example
 Tree cluster
 Arithmetics
 Flow control
  Loops
  Conditions
  Jumps
 MolObjects
 Energy Terms
 Integers
 Reals
 Logicals
 Strings
 Preferences
 Tables
 Other
 Chemical
 Smiles
 Soap
 Gui programming
 Commands
 Functions
 Icm shell functions
 Macros
 Files
Command Line User's Guide
References
Glossary
 
Index
PrevICM Language Reference
Flow control
Next

[ 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.

Prev
Advanced
Home
Up
Next
MolObjects

Copyright© 1989-2018, Molsoft,LLC - All Rights Reserved. Copyright© 1989-2018, Molsoft,LLC - All Rights Reserved. This document contains proprietary and confidential information of Molsoft, LLC. The content of this document may not be disclosed to third parties, copied or duplicated in any form, in whole or in part, without the prior written permission from Molsoft, LLC.