user1060187
user1060187

Reputation: 987

javascript for to while statement

How would I turn these for statements into a while statement in javascript:

    for (left = gridPlace; left <= gridLastPlace; left++){
    for (right = gridOtherPlace; right <= gridLastOtherPlace; right++)
  }

Thanks

Upvotes: 0

Views: 97

Answers (2)

Guffa
Guffa

Reputation: 700412

A for (x; y; z) { ... } is the same as x; while (y) { ... z; }, so your loops would be:

left = gridPlace;
while (left <= gridLastPlace) {
  right = gridOtherPlace;
  while (right <= gridLastOtherPlace) {
    ...
    right++;
  }
  left++;
}

Upvotes: 4

James M
James M

Reputation: 16718

var left = gridPlace;

while(left <= gridLastPlace)
{
    var right = gridOtherPlace;

    while(right <= gridLastOtherPlace)
    {

        right++;
    }

    left++;
}

Upvotes: 1

Related Questions