For문 등에서 배열을 계산하다보면, 인덱스의 범위를 넘어가는 경우가 생긴다. 이때 Mod[footnote]c/c++에서는 %연산자를 이용한다.[/footnote]를 사용하면 편리하다.
(출처 : http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/)
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | '다각형면적구하기[vbnet] Type tPoint   X As Double   Y As Double End Type Function PolygonArea(N As Integer, Points() As tPoint) As Double   Dim i As Integer, j As Integer   Dim area As Double   area = 0   For i = 0 To N - 1     j = (i + 1) Mod N     area = area + Points(i).X * Points(j).Y - Points(j).X * Points(i).Y   Next i   PolygonArea = area / 2 End Function | 
