title: Pausing an ongoing iterative process for user interaction in Kotlin-Android
body: <p>I've been working on a function that going to print given documents via a Bluetooth printer. After sometime, the client wanted to print multiple copies of each document and I've modified my existing code for that purpose.   </p>
  
  <pre><code>&gt; var count = 5
  &gt;         for ((key, value) in printHashMap) {
  &gt;       if (key == "BILL_PRINT"){
  &gt;     
  &gt;                     if (type == "0") {
  &gt;                         
  &gt;     
  &gt;                         for(i in 1 until count) {
  &gt;                             
  &gt;                                 var dialog = SweetAlertDialog(context, SweetAlertDialog.BUTTON_CONFIRM)
  &gt;                                 dialog.setTitleText("Printing Copy ($i)")
  &gt;                                         .showCancelButton(false)
  &gt;                                         .setCancelText("No")
  &gt;                                         .setCancelClickListener { sDialog -&gt;
  &gt;                                             sDialog.dismiss()
  &gt;                                             //need to break the loop exit to the outer For-Loop
  &gt;     
  &gt;                                         }
  &gt;                                         .setConfirmText("Yes")
  &gt;                                         .setConfirmClickListener { sDialog -&gt;
  &gt;                                             sDialog.dismissWithAnimation()                                       
  &gt;     
  &gt;                                             ioScope.launch {
  &gt;                                                 runBlocking {
  &gt;     
  &gt;                                                     if (printingDone(value)) {
  &gt;     
  &gt;                                                         Log.d("Printer", "Printer Done")                                      
  &gt; 
  &gt;     
  &gt;                                                     }else{
  &gt;                                                       Log.d("Printer", "Printer Error")   
  &gt;                                                       //need to break the loop exit to the outer For-Loop
  &gt;                                                     }
  &gt;                                                 }
  &gt;                                             }
  &gt;     
  &gt;                                             prograssDialog.dismissWithAnimation()
  &gt;     
  &gt;                                         }
  &gt;                                         .show()
  &gt;                             
  &gt;                         }
  &gt;     
  &gt;     
  &gt;     
  &gt;     
  &gt;                     }
  &gt;     
  &gt;                 }
  &gt;             }
  </code></pre>
  
  <p>So according to the code, I want to Pause the process for the user confirmation and if the user says 'Yes' then printer should start print the copy of the document. If the user says 'No' then the loop should break out and continue with the outer For-Loop. When I run this function I'm getting the following message on Logcat: </p>
  
  <blockquote>
    <p>Skipped 255 frames!  The application may be doing too much work on its
    main thread.</p>
  </blockquote>
  
  <p>I've even tried While loop blocking and Threading but non of them seems working as expected. What would be the correct way to implement such a use-case? Any kind of guidance would be much appreciated. </p>