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 trialJonathan Fish
7,788 PointsRepeat While Loops
In the swift track taught by Pasan, during the video lesson on While and Repeat while Loops there is a section at the end where he writes a simple repeat while loop which looks like this: var counter = 1 repeat { print("Im in the repeat while loop!") counter++} while counter < 1
However when I try to type this code into Xcode myself a couple things happen:
First, it will not let me use repeat with a lowercase r, instead it forces me to use an uppercase and the color of Repeat becomes dark blue instead of the fuchsia that "while" has.
Second, when I close the curly brackets and try to type "while" I receive an error code telling me to place a semicolon between the curly bracket and the "while" as if they are two different commands on the same line.
Third, I cannot get it to recognize counter as the designated variable when I type it within the curly brackets for repeat i.e. the word "counter" will not appear teal indicating that it is the var I named in the first line.
I am sorry if these are dumb questions but I am completely new to coding and it appears like Swift has changed slightly since this video was made. I have double and triple checked to make sure I am typing exactly what is in the video, including white space and capitalization so I am at a loss even though I am having no problem with the conceptual differences between While and Repeat While. Thanks for any help!
2 Answers
Sathya vegunta
4,061 PointsHi,
All the mentioned issues are because of "Repeat", select "repeat" and the issues will be resolved,while typing repeat we will be getting both the options "Repeat" and "repeat" but the select the one with "r" in lowercase
Anthony Boutinov
13,844 Pointsvar counter = 1; repeat { print("Im in the repeat while loop!"); counter+=1} while counter < 1
Side note: ++ is deprecated in later versions of Swift 2 and is removed in Swift 3
Jonathan Fish
7,788 PointsJonathan Fish
7,788 Pointsthank you for your reply but part of my problem is that when I type repeat with a lowercase r I get an error code that says it is an unrecognized identifier. Right now Xcode will only recognize repeat with a capital R and I'm not sure how to fix that.