title: how to fix mutable variable is accessible from closure warning with a while loop
body: <p>Here's my function that is supposed to validate a name so that there is no duplicates: </p>
  
  <pre><code>function validateBucketName(){
          var counter = 1;
          var validated = false;
          var suggestedName = "Bucket " + (vm.buckets.length + counter);
          if(vm.buckets.length === 0) return suggestedName;
  
          while(!validated){
              var foundIndex = vm.buckets.findIndex(function (bucket) {
                  return bucket.name === suggestedName;
              });
              if(foundIndex === -1){
                  validated = true;
              } else {
                  counter++;
                  suggestedName = "Bucket " + (vm.buckets.length + counter);
              }
          }
          return suggestedName;
      }
  </code></pre>
  
  <p>I am getting the pretty common error, that I am aware of how to deal with in <code>for</code> loops, but can't figure out how to do that with the <code>while</code> loop. Can someone have a look at this? </p>
  
  <p>Ps. This is probably very inefficient way of trying to make sure no duplicate names exist. If you have a suggestion for how to make that better feel free to comment. </p>