2.6. Eureka Ultimatus.   

Our ultimate refinement is to re-analyse the termination conditions since they were derived for the algorithm using a for loop. In this case as soon as symmetric turns false the two while loops will terminate. Therefore we do not need to and it nor use an if construct to get it. We can do a simple assignment. Therefore our final solution is:


symmetric true
row 1
while symmetric and row <= size-1 do
column row+1
while symmetric and column <=size do
symmetric a[row,column]=a[column,row]
column column +1
endwhile
row row +1
endwhile

Write the Java equivalent for this as an exercise.
Note that the Java for loop could use:

       for(row=0;(row<size-1) && symmetric; row++)

:

The middle condition is a while condition and in this case means while row is less than size-1 and symmetric is true. So Java has a nice shortcut. Java has a for loop which can iterate a known number of times as well as terminate on a boolean condition.