title: How can i get the total count in if else condition loop in vb.net?
body: <p>I want to get the total count from the condition for loop, Let's say for the first row(I), the code will check through the if condition, if the condition meets the specific month then use the specific for loop to get the column count (for example : if the row's month is 1 then apply For k As Integer = 4 To dt.Columns.Count - 1 to get the count, if the row's month is 2 then apply For k As Integer = 4 To dt.Columns.Count - 2 to get the count and etc) follow by second row(I) and so on, after the if else condition k then return the total count ,how can i achieve it?    </p>
  
  <p>I have tried the method below but my code below did not work as what had been described above, it only return the count for the first condition,Please guide me on this :</p>
  
  <pre><code>For I As Integer = 0 To dt.Rows.Count - 1
      'If dt.Rows(I).Item("Month").ToString = "1" Or dt.Rows(I).Item("Month").ToString = "3" Or dt.Rows(I).Item("Month").ToString = "5" Or dt.Rows(I).Item("Month").ToString = "7" Or dt.Rows(I).Item("Month").ToString = "8" Or dt.Rows(I).Item("Month").ToString = "10" Or dt.Rows(I).Item("Month").ToString = "12" Then
          For k As Integer = 4 To dt.Columns.Count - 1
              If dt.Rows(I).Item(k).ToString() = "1" Then
                  count1 += 1
              Else
                  count1 = 0
              End If
                 If count1 &gt; 13 Then
                    Dx = True
                   End If
          Next k
      'ElseIf dt.Rows(I).Item("Month").ToString() = "2" Or dt.Rows(I).Item("Month").ToString() = "4" Or dt.Rows(I).Item("Month").ToString() = "6" Or dt.Rows(I).Item("Month").ToString() = "9" Or dt.Rows(I).Item("Month").ToString() = "11" Then
          'For k As Integer = 4 To dt.Columns.Count - 2
              'If dt.Rows(I).Item(k).ToString() = "1" Then
              '   count1 += 1
              'Else
              '   count1 = 0
              'End If
                             ' If total &gt; 13 Then
                  '  Dx = True
                    ' End If
          'Next k
      'End If
  
  
  Next I
  </code></pre>
  
  <p>DataTable (column represents the date, month 11 has 30 columns and month 12 has 31 columns)</p>
  
  <pre><code>    ----------------------------------------------------------------------------
      Id  | year | month | 1  | 2  | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | till 31
      ----------------------------------------------------------------------------
       kek | 2019 | 10     | 1  | 0  | 0 | 1 | 0 | 0 | 1 | 0 | 0 |  0 | 0  |  0 |  1 | 
       kek | 2019 | 11     | 1  | 0  | 0 | 1 | 0 | 0 | 0 | 0 | 0 |  0 | 1  |  1 |  1 | 
       kek | 2019 | 12     | 1  | 1  | 1 | 1 | 1 | 1 | 1 | 1 | 1 |  1 | 1  |  1 |  0 | 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/z3n3D.png" rel="nofollow noreferrer">link</a></p>
  
  <p>Expected Output : </p>
  
  <p>if the consecutive count from 11/11 till 12/12 is more than 13 then dx return true.</p>