How to get out of a cycle in C#?

Question:

I need to exit foreach when the value is equal to 1

foreach (DataGridViewRow dr in dgvValetes)
    if(dr.Cells["valor"].toString()=="1")
        //Sair aqui

I do not know how to do…

Answer:

To exit the cycle use the break command

foreach (DataGridViewRow dr in dgvValetes)
   if (dr.Cells["valor"].ToString()=="1")
      break;
Scroll to Top