4
What’s the error in the loop? I wrote this code to print the sum of the first 10 prime numbers, I’ve reviewed the loops but I couldn’t find the error. It was to print the sum of the cousins until 29 but only printed 2. Vlwzao/
n=2
cont=0
soma=0
while n<=29 do
k=1
while k<=n do
if n%k==0 then
cont=cont+1
end
k=k+1
end
if cont==2 then
soma=soma+n
else soma=soma
end
n=n+1
end
print(soma)
What’s the symptom that tells you there’s some mistake?
– Sorack
at the time of the print of the sum the value I printed is 2, it was to print the sum of the primes until 29.
– Eduardo D. Oliveira
Edit your question and put this information, please
– Sorack
2+3+5+7+11+13+17+19+23+29=129
– Eduardo D. Oliveira
You missed zeroing the variable
cont
within thewhile
– Sorack