title: How to use the variable inside the foreach loop in Java8?
body: <p>This is my actual for-each loop.I need to convert that into java8 for loop.        </p>
  
  <pre><code>for (PromotionEntity promotionEntity : pestudents) {
                  List&lt;ClassAttendanceChild&gt; attendancelist = session.createQuery("from ClassAttendanceChild where attendanceadded='" + day + "' and pid.pId='" + promotionEntity.getpId() + "'").list();
                  if (!attendancelist.isEmpty()) {
                      ClassAttendanceChild attendenceDetails = (ClassAttendanceChild) attendancelist.get(0);
                      if (attendenceDetails.getStatus().equalsIgnoreCase("yes")) {
                          present++;
                          System.out.println("present = " + present);
                      } else {
                          Absent++;
                          System.out.println("Absent = " + Absent);
                      }
                  } else {
                      nottaken++;
                      System.out.println("nottaken = " + nottaken);
                  }
              }
  </code></pre>
  
  <p>How to convert that to java8 for loop,I am getting exceptions in that variable increment:</p>
  
  <pre><code> pestudents.forEach(promotionEntity -&gt; {
              List&lt;ClassAttendanceChild&gt; attendancelist = session.createQuery("from ClassAttendanceChild where attendanceadded='" + day + "' and pid.pId='" + promotionEntity.getpId() + "'").list();
              if (!attendancelist.isEmpty()) {
                   ClassAttendanceChild attendenceDetails = (ClassAttendanceChild) attendancelist.get(0);
                    if (attendenceDetails.getStatus().equalsIgnoreCase("yes")) {
  //                    present++;
  //                    System.out.println("present = " + present);
                  } else {
  //                    Absent++;
  //                    System.out.println("Absent = " + Absent);
                  }
              } else {
  //                nottaken++;
  //                System.out.println("nottaken = " + nottaken);
              }
  
  
          });
  </code></pre>