The Python Oracle

Nested loops with different and dependant steps

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Civilization

--

Chapters
00:00 Question
02:26 Accepted answer (Score 2)
02:58 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