Preloader
Javascript
  • Estimated reading time: 1 Minute

How to print the numbers from 1 to 100 without using loops in JavaScript

A task like printing or storing the numbers within a range e.g from 1 to 100 it's quite intuitive using loops isn't? But what if suddenly a crazy teacher creates an assignment that specifies that you should print the numbers within a range without using loops? It happened to me, so I will be sharing with you the solution for this problem in JavaScript (the logic should work in any other programming language).

Using recursion

The ideal solution uses recursion to print any range of numbers, including negative numbers:

/**
 * This function prints the numbers between a range including them
 * and without using loops (using recursion).
 * 
 * @param start 
 * @param end 
 */
function PrintNumbers(start, end){
    console.log(start);

    if(start < end){
        PrintNumbers((start + 1), end);
    }
}

// Print numbers from 1 to 100 in the console
PrintNumbers(1, 100);

You can see a live example in the following fiddle:

Happy coding ❤️!

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
JavaScript vs. Python for Data Analysis: Key Differences
30 Jan, 2026
  • Estimated reading time: 5 Minutes
Is Framevuerk Still Relevant in 2026?
3 Jan, 2026
  • Estimated reading time: 5 Minutes
The Best JavaScript i18n Libraries Compared
31 Oct, 2025
  • Estimated reading time: 8 Minutes
How to Build a Simple Photo Editor in the Browser with JavaScript
14 Sep, 2025
  • Estimated reading time: 5 Minutes
Weekly trending
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.