# how to run through multiple loops

Page 1 of 1

## 7 Replies - 916 Views - Last Post: 29 November 2013 - 11:33 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=335099&amp;s=31fff87c33bceec9630f03a3247d439f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 vivek20055

Reputation: -7
• Posts: 82
• Joined: 02-November 13

# how to run through multiple loops

Posted 27 November 2013 - 09:08 AM

Hi,

I have 2 columns of data in excel sheet.

I am comparing the first row of first column with all the rows of second column with this code

How can I do the same with all the rows of first column???

```int m = 1;
int p = 1;
for (int n = 1; n < 86; n++)
{

if ((xlWorkSheet.Cells[p, 1].Value.ToString()).Equals((xlWorkSheet.Cells[n, 2].Value.ToString())))

{
xlWorkSheet.Cells[m, 4] = xlWorkSheet.Cells[n, 2];
m++;
}

}
```

Thanks
John

Is This A Good Question/Topic? 0

## Replies To: how to run through multiple loops

### #2 Robin19

Reputation: 272
• Posts: 552
• Joined: 07-July 10

## Re: how to run through multiple loops

Posted 27 November 2013 - 09:24 AM

It looks like 'p' is your row variable. Loop through all values of 'p', using the code you have inside the loop. Do everyone (including yourself) a favor and use more descriptive names.

```var columnARow = 1;
var columnBRow = 1;
var rowsToTest = 86;
var columnDRow = 1;

for( ; columnARow < rowsToTest; columnARow++)
{
for( ; columnBRow < rowsToTest; columnBRow++)
{
var colACell = xlWorksheet.Cells[columnARow, 1].Value.ToString();
var colBCell = xlWorksheet.Cells[columnBRow, 2].Value.ToString();
if (colACell.Equals(colBCell))
{
xlWorksheet.Cells[columnDRow++, 4] = xlWorksheet.Cells[columnBRow, 2];
}
}
}
```

### #3 Skydiver

• Code herder

Reputation: 4845
• Posts: 15,988
• Joined: 05-May 12

## Re: how to run through multiple loops

Posted 27 November 2013 - 09:28 AM

Have another for loop to increment p.

As an aside: Has your C# book still not yet arrived? Has the holiday mail rush delayed the delivery of your book?

Any competent programming book would have covered nested loops. This is another key concept that you are missing out on by trying to jump into the code directly instead of taking time to study and learn. I think the class examples for the nested loop code is to build a multiplication table, and the triangle of asterisks.

### #4 tlhIn`toq

• Freelance developer

Reputation: 6225
• Posts: 13,730
• Joined: 02-June 10

## Re: how to run through multiple loops

Posted 27 November 2013 - 02:54 PM

POPULAR

Delivery of a book? Skydiver you're speaking English, but I don't grasp the concept.

Oh... A co-worker explained it to me. You're talking about one of those old Guttenburg era tomes created on paper using a printing press. How quaint. Do they still do that? Everything I've bought for the last several years is an ePub. I bet I carry 50+ textbooks on my iPad at any given time.

I'd point out that not only is there immediate delivery with electronic publications, but they are cheaper. Plus, I can never get the backlight or search functions to work on those paper publications.

### #5 Michael26

• May the Schwartz be with you

Reputation: 395
• Posts: 1,602
• Joined: 08-April 09

## Re: how to run through multiple loops

Posted 28 November 2013 - 01:23 AM

I sometimes find it difficult to read PDF of the tablet or smartphone, i'm still more comfortable reading real-life paperback copy of a book.

But i see your point, it's easier to carry tablet with 50 PDF then to carry 50 paperback copies with me around, that would look weird.
I can already imagine OP saying "The book is on its way, its gonna be awesome just you wait"

This post has been edited by Michael26: 28 November 2013 - 01:29 AM

### #6 tlhIn`toq

• Freelance developer

Reputation: 6225
• Posts: 13,730
• Joined: 02-June 10

## Re: how to run through multiple loops

Posted 28 November 2013 - 08:33 AM

I agree that .pdf is hard on a tablet. That's because it doesn't reformat or allow you to change type size. Which is why I always get .epub books. You can change the font and font size and the text will re-flow. Most book reader programs also let you change the background color so you can be on true white, paper off white or even reverse to white type on black which is nice reading at night in low light.

### #7 Skydiver

• Code herder

Reputation: 4845
• Posts: 15,988
• Joined: 05-May 12

## Re: how to run through multiple loops

Posted 29 November 2013 - 10:13 AM

I may need to make the leap from Nook to Kindle. Most of by books which have illustrations don't let me see the entire illustration. I was sad when I couldn't see the entire maps from the Lord of the Rings trilogy, or the schematic diagrams and maps from the Honor Harrington series on my Nook and hence I still keep my paper copies of those books.

But I do love the ability to search quickly to find my favorite quotes or find a keyword related to what I need to re-read.

### #8 tlhIn`toq

• Freelance developer

Reputation: 6225
• Posts: 13,730
• Joined: 02-June 10

## Re: how to run through multiple loops

Posted 29 November 2013 - 11:33 PM