Created
August 3, 2023 23:30
-
-
Save ashraf267/1d62da9c9481af9b0da8351d1df2829c to your computer and use it in GitHub Desktop.
I solved a simple: print 1 - 100 without using a loop. I simply used recursion!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// instantiation | |
final noLoop = NoLoop(max: 100); | |
// method call:- prints 1 - 100 | |
noLoop.withoutLoop(); | |
} | |
class NoLoop { | |
static int i = 0; | |
int max; | |
NoLoop({ required this.max }); | |
void withoutLoop() { | |
i += 1; | |
print(i); | |
if (i < max) { | |
// func call again:- recursion | |
withoutLoop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment