+ 1
How does "nested for" work on python?
i just found this code and i don't understand the "nested for" worked (sorry for my bad english i hope you guys understand) https://code.sololearn.com/c8auqmenLbSE/?ref=app
7 ответов
+ 7
hi,
with one more print in your code it becomes clear
https://code.sololearn.com/c4t5S8KgPFh8/?ref=app
+ 5
whenever the outer loop (i ) counts up, the variable is set to zero.
for checking the next number to prime: all other variables backt to their positions.
okay?
+ 5
you need a short docu for the prog. can you do it on your own? Shall we check before your teacher? --> post it.
+ 2
mantapp....
jadi gini:
loop inside loop.
lets call the parent loop is A (5 times) and the child is B (10 times).
when first loop in A, the B is must finish it (10 times) and so on. so, if the B is print('hey') then its gonna print('hey') 50 times.
but the code is mess. should be:
for i in range(1, 10):
if ((i%2)and(i%3)!=0):
print(i, "adalah prima")
else:
print(i, 'bukan prima')
0
how about the variable between both "for"? why does the value change?
0
okay. thanks for the explanation guys.
0
just keep practice until you understand 🤗