Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- l = [ 1, 2, 3 ]
- i = l.__iter__()
- s = None
- while True :
- if s :
- print s
- try :
- s = i.next()
- except StopIteration :
- break
- print "done"
- [stdout:]1
- [stdout:]2
- [stdout:]3
- None['Traceback (most recent call last):
- ', ' File "test_python.py", line 8, in <module>
- s = i.next()
- ', 'StopIteration
- ']
- s = ""
- while True :
- if state is STATE_CODE :
- if "//" in s :
- tokens.add( TOKEN_COMMENT, s.split( "//" )[1] )
- state = STATE_COMMENT
- else :
- tokens.add( TOKEN_CODE, s )
- if state is STATE_COMMENT :
- if "//" in s :
- tokens.append( TOKEN_COMMENT, s.split( "//" )[1] )
- else
- state = STATE_CODE
- # re-evaluate same line
- continue
- try :
- s = i.next()
- except StopIteration :
- break
- while True:
- stuff()
- if fail_condition:
- break
- stuff()
- while not fail_condition:
- stuff()
- for i in l:
- print i
- print "done"
- for s in l:
- while True:
- stuff()
- # use a "break" instead of s = i.next()
- for s in some_list:
- while True :
- if state is STATE_CODE :
- if "//" in s :
- tokens.add( TOKEN_COMMENT, s.split( "//" )[1] )
- state = STATE_COMMENT
- else :
- tokens.add( TOKEN_CODE, s )
- if state is STATE_COMMENT :
- if "//" in s :
- tokens.append( TOKEN_COMMENT, s.split( "//" )[1] )
- break # get next s
- else
- state = STATE_CODE
- # re-evaluate same line
- # continues automatically
- condition = True
- while (condition):
- # loop body here
- condition = test_loop_condition()
- # end of loop
- try:
- while True:
- if s:
- print s
- s = i.next()
- except StopIteration:
- pass
- def coroutine(func):
- """Coroutine decorator
- Coroutines must be started, advanced to their first "yield" point,
- and this decorator does this automatically.
- """
- def startcr(*ar, **kw):
- cr = func(*ar, **kw)
- cr.next()
- return cr
- return startcr
- @coroutine
- def collector(storage):
- """Act as "sink" and collect all sent in @storage"""
- while True:
- storage.append((yield))
- @coroutine
- def state_machine(sink):
- """ .send() new parts to be tokenized by the state machine,
- tokens are passed on to @sink
- """
- s = ""
- state = STATE_CODE
- while True:
- if state is STATE_CODE :
- if "//" in s :
- sink.send((TOKEN_COMMENT, s.split( "//" )[1] ))
- state = STATE_COMMENT
- else :
- sink.send(( TOKEN_CODE, s ))
- if state is STATE_COMMENT :
- if "//" in s :
- sink.send(( TOKEN_COMMENT, s.split( "//" )[1] ))
- else
- state = STATE_CODE
- # re-evaluate same line
- continue
- s = (yield)
- tokens = []
- sm = state_machine(collector(tokens))
- for piece in i:
- sm.send(piece)
- do {
- stuff()
- } while (condition())
- while True:
- stuff()
- if not condition():
- break
- def do_while(stuff, condition):
- while condition(stuff()):
- pass
- while condition is True:
- stuff()
- else:
- stuff()
- loop = True
- while (loop):
- generic_stuff()
- try:
- questionable_stuff()
- # to break from successful completion
- # loop = False
- except:
- optional_stuff()
- # to break from unsuccessful completion -
- # the case referenced in the OP's question
- loop = False
- finally:
- more_generic_stuff()
- while (True):
- generic_stuff()
- try:
- questionable_stuff()
- # to break from successful completion
- # break
- except:
- optional_stuff()
- # to break from unsuccessful completion -
- # the case referenced in the OP's question
- break
- flagBreak = false;
- while True :
- if(flagBreak ) break;
- if s :
- print s
- try :
- s = i.next()
- except StopIteration :
- flagBreak = true;
- print "done"
- for s in l :
- print s
- print "done"
Add Comment
Please, Sign In to add comment