Skip to content

Instantly share code, notes, and snippets.

@ashraf267
Created August 3, 2023 23:30
Show Gist options
  • Save ashraf267/1d62da9c9481af9b0da8351d1df2829c to your computer and use it in GitHub Desktop.
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!
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