Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is it a good idea to create loops only using [functions] instead of traditional [for/while loops]? Is it a good practice? example:

var paper = document.getElementById("paper");

var indexC = 1;

function ciclo(){

    indexC++;
    paper.innerHTML += (indexC + " ");

    if(indexC < 1000){
        ciclo();
    }
}

ciclo();
share|improve this question

closed as primarily opinion-based by j08691, Daniel A. White, Qantas 94 Heavy, giammin, Filipe Gonçalves Mar 4 at 11:59

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
recursion in this case is bad. –  Daniel A. White Nov 7 '13 at 18:42
    
In this case, a for loop would be better. P.S. this is called "recursion". –  Rocket Hazmat Nov 7 '13 at 18:43
    
This may help: stackoverflow.com/a/13346491/538900 –  tchudyk Nov 7 '13 at 18:50
    
Thanks!, I didn't know it's called a "recursion" –  Joel_Rivera Jan 16 at 5:47