title: variable reset to initialize value after for each loop
body: <p>After change value of finalQuizID in if condition in foreach loop, it reset to initialize value in spite of condition is true.
  My Code:</p>
  <pre><code>class SelectQuizActivity : AppCompatActivity() {
  private lateinit var binding: ActivitySelectQuizBinding
  private val mFireStore = FirebaseFirestore.getInstance()
  private var finalQuizID: String = &quot;NULL&quot;
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      binding = ActivitySelectQuizBinding.inflate(layoutInflater)
      setContentView(binding.root)
      binding.btnEnterQuiz.setOnClickListener {
  
          val mQuizID = binding.etQuizId.text.toString().trim { it &lt;= ' ' }
          val finalQuizID = searchOnQuiz(mQuizID)
          if (finalQuizID == mQuizID) {
              val intent = Intent(this, QuizActivity::class.java)
              intent.putExtra(&quot;Quiz ID&quot;, finalQuizID)
              startActivity(intent)
          } else {
              Toast.makeText(
                  this,
                  &quot;Quiz ID didn't match with any Quiz, please make sure you have entered the correct Quiz ID&quot;,
                  Toast.LENGTH_SHORT
              ).show()
          }
      }
  }
  
  private fun searchOnQuiz(quizID: String): String {
      mFireStore.collection(Constants.QUIZ_IDS)
          .get()
          .addOnSuccessListener { doc -&gt;
              kotlin.run loop@{
                  doc.documents.forEach {
                      if (quizID == it.id) {
                          finalQuizID = quizID
                          return@loop
                      } else {
                          finalQuizID = &quot;5&quot;
                      }
                  }
              }
              Log.i(&quot;TAG_after_forEach&quot;, finalQuizID)
          }
      Log.i(&quot;TAG_final&quot;, finalQuizID)
      return finalQuizID
  
  }
  </code></pre>
  <p>Log: TAG_after_forEach: MNP01 (value of quizID parameter)
  TAG_final: NULL</p>