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 trialNathan Noye
4,370 PointsSelecting a certain item in a For In loop
Hey fam,
I'm trying to build an app where it lists 5 or so things and outputs them to a label. Only issue is following the DRY method, I had to use a For In loop so I wouldn't be rewriting a bunch of code. My only issue is when I output this to a Label, my label on displays the bottom item. Is there a way I can make it so it displays everything as a list? for example this is what is should look like
- eggs
- bread
- milk
but it appears as this
- milk
Thanks!
anything helps!
1 Answer
harryg2
5,792 PointsHint: string concatenation, then assign the concatenated string to the label after the loop has run.
Nathan Noye
4,370 PointsThats what I had done initially
lblWork.text = "(randWork)"
only thing is instead of coming out at
- milk
- eggs 3.butter
it came out as 3.butter
it only showed the last item. Any way of making it show all in a list form or sending each item to it's own label?
Note - my code is correct for concatenation but the browser keeps changing it on my side so I'm not sure if the forward slash is appearing or not.
Nathan Noye
4,370 PointsNathan Noye
4,370 PointsNote - I need it to appear as a list in a single label