Using a do loop to print numbers


#1

So my do loop below prints numbers from 1 - 13, however the condition is for it to stop printing when it reaches "11". How would I construct the do loop to make it stop printing at 11?

z = 1
do {
console.log(z);
z = z + 2;

} while (z <= 12);


#2

Hi you can change your while condition like that

while(z < 12)

#3

The code still returns 13!


#4

here

z = z + 2;

change the + 2 with + 1


#5

@codecoder81953,
Try it with

z = 1
do {
 console.log(z);
 z = z + 2;

} while (z <= 12);
console.log("")

The 13 you saw was a value displayed by your Interpreter,
as the last non-displayed z-evaluation,
and by using a dummy-console.log("")
the interpreter will not display it anymore....