title: Is there any way that I can simplify my code using a loop. in Visual Basic
body: <p>I have a program that looks at votes entered for candidates and determines the winner by who has the lowest score. Because the user enters their preferences from 1 to 5 with 1 being the favorite and 5 being the least favorite. If there is a draw the candidate with the most 1's win, if this is still a draw then its the candidate with the most 2's. I have a program but want to know if I can simplify it before I continue to repeat the code to check who got the most 2's ect. This is what I have so far.</p>
  
  <pre><code>    If candidate1 &lt; candidate2 And candidate1 &lt; candidate3 And candidate1 &lt; candidate4 And candidate1 &lt; candidate5 Then
          MsgBox("The winner is" &amp; LblCand1.Text)
      ElseIf candidate2 &lt; candidate1 And candidate2 &lt; candidate3 And candidate2 &lt; candidate4 And candidate2 &lt; candidate5 Then
          MsgBox("The winner is" &amp; lblCand2.Text)
      ElseIf candidate3 &lt; candidate2 And candidate3 &lt; candidate1 And candidate3 &lt; candidate4 And candidate3 &lt; candidate5 Then
          MsgBox("The winner is" &amp; lblCand3.Text)
      ElseIf candidate4 &lt; candidate2 And candidate4 &lt; candidate3 And candidate4 &lt; candidate1 And candidate4 &lt; candidate5 Then
          MsgBox("The winner is" &amp; lblCand4.Text)
      ElseIf candidate5 &lt; candidate2 And candidate5 &lt; candidate3 And candidate5 &lt; candidate4 And candidate5 &lt; candidate1 Then
          MsgBox("The winner is" &amp; lblCand5.Text)
      ElseIf C1V1s &gt; C2V1s And C1V1s &gt; C3V1s And C1V1s &gt; C4V1s And C1V1s &gt; C5V1s Then
          MsgBox("The winner is" &amp; LblCand1.Text)
      ElseIf C2V1s &gt; C1V1s And C2V1s &gt; C3V1s And C2V1s &gt; C4V1s And C2V1s &gt; C5V1s Then
          MsgBox("The winner is" &amp; lblCand2.Text)
      ElseIf C3V1s &gt; C1V1s And C3V1s &gt; C2V1s And C3V1s &gt; C4V1s And C3V1s &gt; C5V1s Then
          MsgBox("The winner is" &amp; lblCand3.Text)
      ElseIf C4V1s &gt; C1V1s And C4V1s &gt; C2V1s And C4V1s &gt; C3V1s And C4V1s &gt; C5V1s Then
          MsgBox("The winner is" &amp; lblCand4.Text)
      ElseIf C5V1s &gt; C1V1s And C5V1s &gt; C2V1s And C5V1s &gt; C3V1s And C5V1s &gt; C4V1s Then
          MsgBox("The winner is" &amp; lblCand5.Text)
      End If
  </code></pre>