简体   繁体   中英

c# for each progress loop within the loop

I have a situation where I am looping through ac# webpages database recordset using for each record in records.

Within that loop I also want to perform another do while loop so that records can be grouped together.

Is it possible to increase the iteration of the for next loop from within the loop..hard to explain but something like this

 foreach (var records in records){

 do{
   <p>@records.NAME</p>
   INCREASE THE FOREACH LOOP ITERATION HERE
   currentName = records.NAME //this is now the next name in the recordset
 }while(currentName!=records.NAME)

 }

Thanks Rolf

It is best to do a for loop for this type of method

for (int index = 0; index < records.Count - 1; index++){

do{
   <p>@((records)records.Item(index)).NAME</p>
   index++;
   If(index < records.Count) {
      currentName = ((records)records.Item(index)).NAME; //this is now the next name in the recordset
   Else{
      Break;//Breaks out of the while loop because you are done with the for loop }
   }
}while(currentName!=((records)records.Item(index)).NAME)

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM