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:
- method() {
- while(condition) {
- do_stuff();
- }
- // return stuff
- }
- // And its recursive counterpart:
- method() {
- if(condition) {
- do_stuff();
- method();
- }
- // return stuff
- }
- // Same thing, but with a do-while loop instead:
- method() {
- do {
- do_stuff();
- } while (condition);
- // return stuff
- }
- // And its recursive counterpart:
- method() {
- do_stuff();
- if(condition) {
- method();
- } else {
- // return stuff
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement