(while() ..., do ... while(), for() ...), , , .
:
var loopCounter = 3;
function loop() {
document.write(loopCounter + '<br>');
loopCounter--;
loopCounter && loop();
}
loop();
Needless to say, this structure is often used in conjunction with the return value, so this is a small example of how to deal with a value that is not available the first time, but at the end of the recursion:
function f(n) {
return +!~-n || n * f(n - 1);
}
document.write(f(7));
Run code source
share