By Kardi Teknomo

This is a very simple tutorial on programming for fresh programmers. The problem goes like this:

You have a symmetric table or matrix size Programming Tips: How to Iterate over a Symmetric Table? by Programming Tips: How to Iterate over a Symmetric Table? and you want to do something (i.e. evaluate or simply print) based on the content of the matrix. Because the matrix is symmetric, you do not need to iterate over the whole matrix. You can iterate over upper triangular part only or lower triangular part only and get the same results. How to do that in the program?

Solution:

To be precise, you have square symmetric matrix

Programming Tips: How to Iterate over a Symmetric Table?

and you want to iterate over

Upper triangular matrix without diagonal, or

Upper triangular matrix with diagonal, or

Lower triangular matrix without diagonal, or

Lower triangular matrix with diagonal

Upper triangular matrix without diagonal

Programming Tips: How to Iterate over a Symmetric Table?

Pseudo Code: 
For row = 1 to (q-1) 
     For col = (row + 1) to q 
          Print A (row, col) ?// do something 
     Next col 
Next row 

Number of members printed: Programming Tips: How to Iterate over a Symmetric Table?

Upper triangular matrix with diagonal

Programming Tips: How to Iterate over a Symmetric Table?

Pseudo Code: 
For row = 1 to q 
     For col = row to q 
          Print A (row, col) ?// do something 
     Next col 
Next row 

Number of members printed: Programming Tips: How to Iterate over a Symmetric Table?

Lower triangular matrix without diagonal

Programming Tips: How to Iterate over a Symmetric Table?

Pseudo Code: 
For col = 1 to (q-1) 
     For row = (col + 1) to q 
          Print A (row, col) ?// do something 
     Next col 
Next row 

Number of members printed: Programming Tips: How to Iterate over a Symmetric Table?

Lower triangular matrix with diagonal

Programming Tips: How to Iterate over a Symmetric Table?

Pseudo Code: 
For col = 1 to q 
     For row = col to q 
          Print A (row, col) ?// do something 
     Next col 
Next row 

Number of members printed: Programming Tips: How to Iterate over a Symmetric Table?

See Also: VB Tutorial