The Python Oracle

Nested loops with different and dependant steps

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping

--

Chapters
00:00 Nested Loops With Different And Dependant Steps
02:03 Accepted Answer Score 2
02:26 Thank you

--

Full question
https://stackoverflow.com/questions/6571...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #python3x #performance #forloop #whileloop

#avk47



ACCEPTED ANSWER

Score 2


This might help you some. (Not exactly what you wanted but it is a start)

j = 0
h = 50
while j <= h:
    n = h/2 - j
    if -3 <= n <= 3:
        i = j
        while i < j + 10:
            n = h/2 - i
            if n <= 0:
                j = h + 70
                print(n)
                break
            i += 0.1
    j += 3

or you could do it like this.

j = 0
h = 50
while j <= h:
  n = h/2 - j
  if -3 <= n <= 3:
    break
  j += 3

i = j
while i < j + 10:
  n = h/2 - i
  if n <= 0:
      print(n)
      break
  i += 0.1