58 lines
1.1 KiB
Plaintext
58 lines
1.1 KiB
Plaintext
'Loops Increment loop index within loop body - 16/07/2018
|
|
imax=42
|
|
i=0
|
|
n=42
|
|
While i<imax
|
|
isprime_n()
|
|
If ret_isprime_n Then
|
|
i=i+1
|
|
format_i()
|
|
format_n()
|
|
TextWindow.WriteLine("i="+ret_format_i+" : "+ret_format_n)
|
|
n=n+n-1
|
|
EndIf
|
|
n=n+1
|
|
EndWhile
|
|
|
|
Sub isprime_n
|
|
If n=2 Or n=3 Then
|
|
ret_isprime_n="True"
|
|
ElseIf Math.Remainder(n,2)=0 Or Math.Remainder(n,3)=0 Then
|
|
ret_isprime_n="False"
|
|
Else
|
|
j=5
|
|
While j*j<=n
|
|
If Math.Remainder(n,j)=0 Or Math.Remainder(n,j+2)=0 Then
|
|
ret_isprime_n="False"
|
|
Goto exitsub
|
|
EndIf
|
|
j=j+6
|
|
EndWhile
|
|
ret_isprime_n="True"
|
|
EndIf
|
|
exitsub:
|
|
EndSub 'isprime_n
|
|
|
|
Sub format_i
|
|
ret_format_i=Text.GetSubText(" ",1,3-Text.GetLength(i))+i
|
|
EndSub 'format_i
|
|
|
|
Sub format_n
|
|
nn=""
|
|
l=-1
|
|
For k=Text.GetLength(n) To 1 Step -1
|
|
l=l+1
|
|
cc=Text.GetSubText(n,k,1)
|
|
If l=3 Then
|
|
cv=","
|
|
l=0
|
|
Else
|
|
cv=""
|
|
EndIf
|
|
nn=Text.Append(cc,Text.Append(cv,nn))
|
|
EndFor
|
|
space=" "
|
|
nn=Text.GetSubText(space,1,Text.GetLength(space)-Text.GetLength(nn))+nn
|
|
ret_format_n=nn
|
|
EndSub 'format_n
|