- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Recursive loop that prints an inverted count in JavaScript
We are required to write a recursive JavaScript function that takes in a number and print the reverse count until 0 from that number. The only condition for us is that we have to write this function making use of recursion only.
Example
The code for this will be −
const recursiveLoop = (counter) =>{ if(counter > 0){ recursiveLoop(counter - 1); }; console.log(counter); return counter; } recursiveLoop(5); recursiveLoop(15); recursiveLoop(25)
Output
And the output in the console will be −
0 1 2 3 4 5 0 1 2 3 456789 10 11 12 13 14 150123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
- Related Articles
- JavaScript recursive loop to sum all integers from nested array?
- JavaScript function that should count all unique items in an array
- JavaScript Quicksort recursive
- Count of pairs in an array that have consecutive numbers using JavaScript
- Using merge sort to recursive sort an array JavaScript
- Recursive multiplication in array - JavaScript
- Recursive Staircase problem in JavaScript
- C Program that receives a number and prints it out in large size
- Using a recursive function to capitalize each word in an array in JavaScript
- Setting property in an empty object using for loop in JavaScript.
- Count consonants in a string (Iterative and recursive methods) in C++
- Python Program that prints the rows of a given length from a matrix
- The while loop in Javascript
- Count half nodes in a Binary tree (Iterative and Recursive) in C++
- Count full nodes in a Binary tree (Iterative and Recursive) in C++

Advertisements