RosettaCodeData/Task/Loops-Increment-loop-index-within-loop-body/FreeBASIC/loops-increment-loop-index-within-loop-body.basic
2023-07-01 13:44:08 -04:00

38 lines
780 B
Text

' version 18-01-2019
' compile with: fbc -s console
Function isprime(number As ULongInt) As UInteger
If number Mod 2 = 0 Then Return 0
If number Mod 3 = 0 Then Return 0
Dim As UInteger i, max = Sqr(number)
For i = 5 To max Step 2
If number Mod i = 0 Then Return 0
Next
Return 1
End Function
' ------=< MAIN >=------
Dim As UInteger counter
Dim As ULongInt i
Print : Print
counter = 0
For i = 42 To &HFFFFFFFFFFFFFFFF ' for next loop, loop maximum = 2^64-1
If isprime(i) Then
counter += 1
Print Using "n =### ##################,"; counter; i
If counter >= 42 Then Exit for
i += i -1
End If
Next
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End