title: How to stop Kotlin flow when certain condition occurs
body: <p>I want to cancel kotlin flow if certain condition occurred in code.</p>
  
  <p>Suppose i have a method as following</p>
  
  <pre><code>fun test(): Flow&lt;String&gt; = flow {
      val lst = listOf("A", "B", "C")
  
      while(true) {
          lst.forEach { emit(it) }
  
      //If some condition occurs, need to return from here, else continue
      //How to stop flow here
      }
  }
  </code></pre>
  
  <p>and calling it like </p>
  
  <pre><code>test().collect { println(it)}
  </code></pre>
  
  <p>question is, how to stop flow to produce anything on certain conditions (from flow builder or outside of it)? </p>