1

i'm trying to make do...while loop with reversed order and with "random step".

var estam = 100;
do
{

   //   some things, that can change variable "rd"

   estam -= Math.floor((Math.random()*rd)+1)
}
while (estam < 1);

But browsers just perform do once.

I'm trying to get: "do something with some things and decrease variable estam accordingly to those things (and those some operations) as long as estam is bigger than zero".

Or i need to make ordinary loop with steps, and in each step check estam than jump out to function and back ?

2
  • 1
    If you want it to loop while estam is bigger than zero, you should specify that in the while condition as estam > 0. What you have now is not equivalent to what you say you want. Commented Dec 27, 2013 at 23:51
  • I thought that last line while (estam < 1); is the conditional limit to break te loop. My mistake. Commented Dec 28, 2013 at 0:37

1 Answer 1

1

The do while expression should be read as "do this work while this expression is true".

You are looking for

while (estam > 0);

which will ensure the loop breaks once estam is less than 0, when the expression is no longer true.

Sign up to request clarification or add additional context in comments.

1 Comment

So simple, I thought that last line while (estam < 1); is the conditional limit to break te loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.