title: How to write multiple conditions in Kotlin for loop
body: <p>This is the following code I have</p>
  
  <pre><code>val idNumber: String = "1342342"
  var randomNumber = 0
  
  for (number in idNumber) {
      if (randomNumber &lt; 20) {
          // Do something
          randomNumber++
      }
  }
  </code></pre>
  
  <p>Here I've a for loop which <em>iterates through the idNumber</em> and at the same time I've to check if <em>randomNumber is less than 20</em>.</p>
  
  <p>In Java, I can write this as</p>
  
  <pre><code>for (int i = 0 ; i &lt; idNumber.length() &amp;&amp; randomNumber &lt; 20 ; i++) {
  
  }
  </code></pre>
  
  <p>How do I do the same in Kotlin?</p>
  
  <p>I went through Stackoverflow for this problem and found this <a href="https://stackoverflow.com/questions/45230577/how-to-make-multiconditional-for-loop-in-kotlin">solution</a> which explains to <em>use a more functional approach</em>. Please suggest me a good solution for the problem I mentioned above.</p>
  
  <p><strong>Edit 1: I understand that while loop can be used to do a logical and, but I would like to know what's the functional way of solving this</strong>.</p>
  
  <p><strong>Edit 2: Added answer, but still would love to hear from someone who can give a better insight to this problem</strong></p>