I created a loop without using any built-in loops!

Sameera BegumSameera Begum
1 min read

In basic loops we have three parameters.

  1. Initialization

  2. Condition

  3. Increment/Decrement

So I initialize variables with a starting value and an ending value.

Then I created a function where it prints the starting value.

After that, I recursively invoked that function by passing the parameter as starting value + 1 if incrementing, otherwise starting value -1 for decrementing, until it is equal to the ending value.

Let’s assume the ending value as n; then the time complexity for this will be O(n).

0
Subscribe to my newsletter

Read articles from Sameera Begum directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sameera Begum
Sameera Begum