I am trying to use a do...while loop that loops based on the id's in my array. I am a little new to using the do while loop, so am having some trouble incorporating the array into the thing. Here is my relevant code:
String studentId = StringUtils.defaultString(request.getParameter("Student_ID"));
String studentId1 = StringUtils.defaultString(request.getParameter("Student_ID1"));
String studentId2 = StringUtils.defaultString(request.getParameter("Student_ID2"));
String studentId3 = StringUtils.defaultString(request.getParameter("Student_ID3"));
String studentId4 = StringUtils.defaultString(request.getParameter("Student_ID4"));
String studentId5 = StringUtils.defaultString(request.getParameter("Student_ID5"));
String studentId6 = StringUtils.defaultString(request.getParameter("Student_ID6"));
String studentId7 = StringUtils.defaultString(request.getParameter("Student_ID7"));
String studentId8 = StringUtils.defaultString(request.getParameter("Student_ID8"));
String studentId9 = StringUtils.defaultString(request.getParameter("Student_ID9"));
String[] studentArray;
studentArray = new String [15];
studentArray[0] = studentId; studentArray[1] = studentId1;
studentArray[2] = studentId2; studentArray[3] = studentId3;
studentArray[4] = studentId4; studentArray[5] = studentId5;
studentArray[6] = studentId6; studentArray[7] = studentId7;
studentArray[8] = studentId8; studentArray[9] = studentId9;
do {
// blah blah blah
} while ( // Here is where I want to tell it to loop for every student in my array. It should not run for id's that are empty strings(*if possible));
See comments for a more clear explanation. The StringUtils.defaultString that is used when i am getting my parameters will give me an empty string if the param receives a NULL. So if possible I would like to take that into account, and not run my "do {}" statements when the particular array ID is an empty string. Thanks in advance for the help, and if you have any questions, please ask.
studentArray.lengthwill tell you how many elements are in the array. It's easier to iterate over the array withfor (int i = 0; i < studentArray.length; i++), but you can simulate that withdo/whileif you keep and "manually" increment/test your own index variable.