-1

#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?#

1
  • 3
    Does this answer your question? for loop in Python Commented Jun 29, 2020 at 7:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.