When I'm iterating over two arrays at once, which one do I use as the limit?

Posted by Martijn Courteaux on Stack Overflow See other posts from Stack Overflow or by Martijn Courteaux
Published on 2010-03-08T19:12:00Z Indexed on 2010/03/08 19:21 UTC
Read the original article Hit count: 272

Hi,

I'm always struggling with something like the following Java example:

String breads[] = {"Brown", "White", "Sandwich"};
int count[] = new int[breads.length];
for (int i = 0; i < ****; i++)
{
   // Prompt the number of breads
}

****: which array.length should I choose?
I can choose between breads.length and count.length
I know it would be the same result, but I don't know which one I shoud choose.

There are many other examples where I get the same problem.
I'm sure that you have encountered this problem as well in the past.

What should you choose? Are there general agreements?

Thanks

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about subjective