Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Shayan Khan
Shayan Khan
9,842 Points

How do I print numbers in array using a while loop and the println command?

I don't understand how to print numbers in an array using a while loop.

1 Answer

Hi Shayan!

To do this you will need to specify a counter variable and then use that counter variable as the index of the array! This may seem confusing at first but don't worry!

The code below won't work for you in this case as it is more of an algorithm than actual code but it should give you a good idea of how this type of thing would work!

while(condition) {

That should give you a bit of a start on working out the solution for this problem! Good luck and if you need any more help feel free to ask!


Shayan Khan
Shayan Khan
9,842 Points

Thanks Luke! Appreciate your help.