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 trialMark Bekhet
900 PointsUsing for loops instead of while loops
I have done the same steps that is shown in this video but I tried to use the for loop instead of the while one, but it says to me that I have a syntax error I don<t understand the reason
1 Answer
Alexander Davison
65,469 PointsHi Mark,
Can you please provide your code? We can't really help much without seeing your code. Also, it may help to provide the error. Remember to use the proper markdown to show your code. Refer to the Markdown Cheatsheet below the answer box.
sleconte
2,591 Pointssleconte
2,591 PointsYou would have to use a range when using a for loop and make sure that the for loop does not continue beyond when the number of tickets is less than zero.
The trouble is that if you are prompting the user for the number of tickets to purchase in each iteration of the for loop, the number of loops required to exhaust the supply of tickets is unpredictable - somebody could buy all tickets at once for example.