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

sana

New member
Joined
Feb 12, 2014
Messages
2
Programming Experience
1-3
Hi,
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.

C#:
 while (iRow <= count-1)                 {
                     read.Read(); 
                      
                    if (iTopMargin >=  240)
                    {
                        bMorePagesToPrint = true;
                       
                        break;


                    }

Please can you help in this probleme
Thank you
 
Can i have an equivalent to this code to read result of sqdatreader
C#:
    while (iRow <= dataGridListe.Rows.Count - 1)
instead of
C#:
    while (reader.read())
 
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?

C#:
while (iRow <= dataGridListe.Rows.Count - 1) {
                    if (read.Read()) break; 
                      
                    if (iTopMargin >=  240)
                    {
                        bMorePagesToPrint = true;
                       
                        continue;
                    }
 
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.
 
Back
Top Bottom