1! Program to test nested forall
2program forall2
3  implicit none
4  integer a(4,4,2)
5  integer i, j, k, n
6
7  a(:,:,1) = reshape((/ 1, 2, 3, 4,&
8                        5, 6, 7, 8,&
9                        9,10,11,12,&
10                       13,14,15,16/), (/4,4/))
11  a(:,:,2) = a(:,:,1) + 16
12  n=4
13  k=1
14  ! Mirror half the matrix
15  forall (i=k:n)
16   forall (j=1:5-i)
17     a(i,j,:) = a(j,i,:)
18   end forall
19  end forall
20
21  if (any (a(:,:,1) &
22      .ne. reshape((/ 1, 5, 9,13,&
23                      2, 6,10, 8,&
24                      3, 7,11,12,&
25                      4,14,15,16/),(/4,4/)))) STOP 1
26  if (any (a(:,:,2) .ne. a(:,:,1) + 16)) STOP 2
27end
28