title: In Kotlin, how do you modify the contents of a list while iterating
body: <p>I have a list:</p>
  
  <pre class="lang-kotlin prettyprint-override"><code>val someList = listOf(1, 20, 10, 55, 30, 22, 11, 0, 99)
  </code></pre>
  <p>And I want to iterate it while modifying some of the values.  I know I can do it with <code>map</code> but that makes a copy of the list.</p>
  <pre class="lang-kotlin prettyprint-override"><code>val copyOfList = someList.map { if (it &lt;= 20) it + 20 else it }
  </code></pre>
  <p>How do I do this without a copy?</p>
  <p><strong>Note:</strong> <em>this question is intentionally written and answered by the author (<a href="https://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/">Self-Answered Questions</a>), so that the idiomatic answers to commonly asked Kotlin topics are present in SO.  Also to clarify some really old answers written for alphas of Kotlin that are not accurate for current-day Kotlin.</em></p>