what am i doing wrong here? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
25th Jul 2021, 6:20 PM
CodeSmith
CodeSmith - avatar
4 Respuestas
+ 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?
25th Jul 2021, 6:33 PM
CodeSmith
CodeSmith - avatar
+ 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
25th Jul 2021, 6:37 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 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?
25th Jul 2021, 6:41 PM
CodeSmith
CodeSmith - avatar
+ 1
✩✮★✮✩ thanks, so i guess "let" suits better for loops.
25th Jul 2021, 6:55 PM
CodeSmith
CodeSmith - avatar