can't repeat function inside while True

Asked by david on 2016-12-24

hello, i can't get this piece of code working and i have no idea as to why...

def ABC():
    while True:
        some codes
################################
(Mainloop)
while True

    some codes

    ABC()

   some codes

the above code repeats mainloop indefinitely,
and when it arrives at the ABC() function, it should indefinitely repeat ABC(), until the code breaks when it fulfills the condition that requires it

however, what i am experiencing is, the ABC() only goes through once.
it doesn't repeat, it's as if "while True" inside def ACB() is being ignored...
so, it just goes through ABC and continues on with the rest of the codes in main loop...

can somebody help me please T.T...

i can't solve this on my own... please help...

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2016-12-24
Last reply:
2016-12-25
Alex Lunyov (lunyov-av) said : #1

At first check the breaking condition of ABC() infinite cycle. Check using of global and local variables in "Mainloop" and ABC loop.

david (dovidu) said : #2

the strange thing is , even if the breaking condition is not included in the ABC() infinite cycle, it still goes through only once, and continues on back to the main loop...

RaiMan (raimund-hocke) said : #3

this simply does what it should.
So just check your code agains this template:

nMax = 3
nMain = 0

def sub():
  nSub = 0
  while True:
    # some additional code here
    # prepare break check
    nSub += 1
    if nSub > nMax: break # check break condition
    print "sub:", nSub
    # some additional code here

while True:
  # some additional code here
  # prepare break check
  nMain += 1
  if nMain > nMax: break # check break condition
  print "main:", nMain
  sub()
  # some additional code here

Can you help with this problem?

Provide an answer of your own, or ask david for more information if necessary.

To post a message you must log in.