Jul 1 2004
Contents
 
Introduction
Reference Guide
 ICM command line options
 Command line editing
 Graphics controls
 Editing pairwise sequence-structure alignments
 Constants
 Subsets and index expressions
 Molecule intro
 Selections
 Arithmetics
 Flow control
  Loops
  Conditional branching
  Jumps
 ICM molecular objects
 Energy and Penalty Terms
 Integer shell parameters.
 Real shell variables
 Logical variables
 String variables
 Preferences
 Tables (structures)
 Other shell variables
 Commands
 Functions
 Macros
 Files
User's guide
References
Glossary
 
Index
Prev
2.10 Flow control
Next

[ il2 | icmbranching | ij ]

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

2.10.1 Loops

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

2.10.2 Conditional branching

[Top]
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 


2.10.3 Jumps

[Top]
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
advancedoper
Home
Up
Next
im7

Copyright© 1989-2004, 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.