Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Loop structures can always be expressed as recursion
- # Here's an example with a simple while loop:
- def method():
- while condition:
- do_stuff()
- # return stuff
- # And its recursive counterpart:
- def method():
- if condition:
- do_stuff()
- method()
- # return stuff
- # Same thing, but with a 'do-while' loop instead:
- def method():
- while True:
- do_stuff()
- if not condition:
- break
- # return stuff
- # And its recursive counterpart:
- def method():
- do_stuff()
- if condition:
- method()
- else:
- # return stuff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement