A.11.3.  for Loops

for loops are control statements that are a basic looping construct in C. They are analogous to do loops in FORTRAN. The format of a for loop is

for (begin ; end ; increment)
  {statements} 

where begin is the expression that is executed at the beginning of the loop; end is the logical expression that tests for loop termination; and increment is the expression that is executed at the end of the loop iteration (usually incrementing a counter).

A.11.3.1. Example

/* Print integers 1-10 and their squares */
 
 int i, j, n <= 10;
 
 for (i = 1 ; i = n ; i++)
   {
    j = i*i;
    printf("%d %d\n",i,j);
   } 

The equivalent FORTRAN code is shown below for comparison.

   INTEGER I,J
   N = 10
   DO I = 1,10
   J = I*I
   WRITE (*,*) I,J
   ENDDO 

Release 18.2 - © ANSYS, Inc. All rights reserved.