+ 1
what am i doing wrong here?
4 Respostas
+ 1
✩✮★✮✩ thanks it worked,
but i dont understand, since 'i' is within functions and not declared outside they should be local? or is it that i passed 'i' as argument to another function with 'i' variable?
+ 1
~LoneWolf
There are loops in to function like
function isprime(n)
function allprimes(n)
allprimes (n) function calls
isprime (n) function
Both has for loop in those function share common global variable I
That makes code giving clumsy output as both function manipulate global variable i
so for loop needs to be written like
for (var i = 2; I < num; I++)
instead of
for (I = 2; I < num; I++)
It will fix the code
DHANANJAY PATEL
+ 1
DHANANJAY PATEL thanks i am going to use "var" everytime now when declaring 'i' within loop. or shall i use "let" whats the difference between both?
+ 1
✩✮★✮✩ thanks, so i guess "let" suits better for loops.