Given the following for
loop statement, convert it to while
counterpart.
let total = 0;
for (let i=1 ; i < 20 ; i++) {
total = total + i;
}
console.log("The total is " + total);
What is expected
By going through this exercise, you will understand how similar for and while are as far the task is concerned. So the while, at the end, shall work just like the way for works as far as the result is concerned.
Hint: On the case of for loop, the counter is handled by the for construct itself. On the case of the while, the programmer needs to track that.