![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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).
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 |