title: Protractor break while of for loop
body: <p>I need help with loop beaking.</p>
  
  <p>For my check I did the simple test:</p>
  
  <pre><code>while(i &lt; 10) {
      element(by.xpath("//a[contains(@id, 'ma-apply')]")).isPresent().then(function(result) {
          if(!result) {
              helper.one_page_ahead();
          } else {
              console.log('there is on the page');
              break;
          }
      });
      i++;
  };
  </code></pre>
  
  <p>This code leads to the error.</p>
  
  <p>I tried to follow advice via StackOverflow and changed break to return.
  But this leads to full loop execution (up to 10).</p>
  
  <p>Here is the output:</p>
  
  <blockquote>
    <p>[14:17:46] I/launcher - Running 1 instances of WebDriver Started user
    skills: AJAX there is on the page there is on the page there is on the
    page there is on the page there is on the page there is on the page
    there is on the page there is on the page .</p>
    
    <p>1 spec, 0 failures Finished in 37.93 seconds</p>
  </blockquote>
  
  <p>I tried the same with <code>for</code> loop like </p>
  
  <pre><code>for(i = 0; i &lt; 10; i++) {
      //code
      break;
  }
  </code></pre>
  
  <p>Would be glad to find the answer.</p>