Why Does This Work?
To All,
I have found this nested For/Next loop designed to generate the prime numbers up to a certain number, in this case 13.
My question is why does the following code work as it is written? I have highlighted the portion in red that I don't understand. I could have generated this code myself but I would have written it with the red highlighted portion deleted, and by the way I find that the code works well with the red hightlighted portion present or deleted.
From my perspective, I don't understand why it would work with the hightlighted portion included, that is I don't understand why the final value of 13 would be included if the most that j could be is j-1 or 12. It would seem that you could never reach 13/13 or mod =0 for the final value of 13.
Any thoughts?
For i = 3 To 13
For j = 2 To i - 1
If (i Mod j) = 0 Then
Exit For
End If
Next
If (i = j) Then
Console.Out.Write("{0} ", j)
End If
Next
Console.Out.WriteLine()
Thank you for any insight,
Little Shell
|