
Patrick B. answered 10/20/20
Math and computer tutor/teacher
'returns the first integer that divides x evenly if not prime, x otherwise
Public Function IsPrime(x As Integer) As Integer
Dim iReturn As Integer
iReturn = x
For iLoop = 2 To x / 2 + 1
If x Mod iLoop = 0 Then
iReturn = iLoop
End If
Next iLoop
IsPrime = iReturn
End Function
Sub Main()
Dim N As Integer
N = 100
For iLoop = 2 To N
If IsPrime(iLoop) = iLoop Then
Console.WriteLine(iLoop)
End If
Next
End Sub
End Module