


We are then initializing a while loop that is going to stop when i is greater than 50. The first to realize is that we are starting off with i=2. Now, let us approach what is going on inside of this code.

The second thing that we are able to do is see what is being incremented where. The first thing we are able to do is get a nice visual of what is inside of what, instead of assuming anything. i = 2īy writing the code like this, we are able to do several things. Did I miss any increments here? Thank you.įirst of all, I would like to post the correct syntax for the code. And I want to know what part I did wrong here. But (3 <= (6/3)) <- this is not true, so it goes to if statement and 3 which is j is bigger than 2 which is i/j, which means 6 should be prime.īut it's not. So j should still be 3 and i should be 6. So j should be 3 and i should be 5, 5 is prime, then it increments again to 6. Then it's not a prime number, so it goes back to the while loop.Īnd the process starts over. So after 3, j should be 2 and i should be 4. I am new to python and I am having some problems with this code that should print all the prime numbers that are smaller than 50 using nested loops.
