break in while and start reading from where it was left earlier


New member
Feb 12, 2014
Programming Experience
I have a while loop to read result of datareader in which I added a test with a break.
when the break will execute the while loop is repeated from the beginning instead of continuing from where it was left earlier.

 while (iRow <= count-1)                 {
                    if (iTopMargin >=  240)
                        bMorePagesToPrint = true;


Please can you help in this probleme
Thank you
Can i have an equivalent to this code to read result of sqdatreader
    while (iRow <= dataGridListe.Rows.Count - 1)
instead of
    while (
First of all, 'while' loops don't have a beginning. They simply keep run while a condition is true. If you think that your loop has a definite beginning then you should be using a 'for' loop and not a while loop. If you're trying to loop through the items of a collection by index then absolutely you should be using a 'for' loop. The loop will start with the loop counter at whatever value you want it to start with. If you want it to start at zero then start at zero. If you want it to start at some other value then start it at some other value. How do you usually store a value that varies over time? In a variable of course.
I'm not sure what you mean. Maybe this?

while (iRow <= dataGridListe.Rows.Count - 1) {
                    if (read.Read()) break; 
                    if (iTopMargin >=  240)
                        bMorePagesToPrint = true;
No I didn't understand the op's question. His title was

I think he was asking how to continue

Oops! Sorry, I thought that you were the OP answering me. Didn't look at the names properly.
Top Bottom