Hi all,

I'm working on a program for my data handling class and I have a quick question. I'm trying to write a method that prints a range of elements in an array. I have written it in such a way that I create a new, smaller array with the specified first and last element, but I was wondering if there way to do this with an enhanced for statement. It seems like it would be so much more elegant, but I can't seem to find any sample code for this. There is more to the program that this and I don't want anyone to do this for me, I'm just looking for a way to write the enhanced for statement using an upper and lower bound. Thanks for any replies.

Steve

Recommended Answers

All 2 Replies

Nope! If you only want to loop over a "sub array" the "old" for loop is better. An alternative, if it is an Object array, is to stop looping (break) at the first null object.

Nope! If you only want to loop over a "sub array" the "old" for loop is better. An alternative, if it is an Object array, is to stop looping (break) at the first null object.

That's what I kind of figured. Thanks for the help anyways. I managed to get it anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.