#In C/C++, I can have the following loop#
for(int j = i * i; j <= N ;j += i)
#How do the same thing in Python?#
Asked
Active
Viewed 23 times
-1

Raj Sen
- 13
- 2
-
3Does this answer your question? [for loop in Python](https://stackoverflow.com/questions/4170656/for-loop-in-python) – b3rt0 Jun 29 '20 at 07:52
1 Answers
0
this might work:
from itertools import count
N = 11**2
i = 2
for j in count(start=i**2, step=i):
if j**2 > N:
break
print(j)
itertools.count
starts at i**2
this way and counts up in steps of i
. then i use the break
statement to break the loop if the condition j**2 > N
is met.

hiro protagonist
- 44,693
- 14
- 86
- 111