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 trialswiftfun
4,039 PointsHow to execute this IF statement?
First, please excuse me if the question is rather non-sense.
Is there any way of adding RANGES to an integer in an IF statement?
"if temperature is between 10...20"
2 Answers
Christin Lepson
24,269 PointsYes, you can absolutely use ranges in an if statement. After the "if" you provide two requirements- temperature is greater than 10 and temperature is less than 20. You join these two requirements by using &&, which in swift means AND. Here's an example:
if temperature>10 && temperature<20 {
print("Yes, it is between 10 and 20.")
} else {
print("No, it is not between 10 and 20.")
}
AFIR MOURAD TAHAR
3,766 PointsHello,
If in php
//testing if statement
if (temperature >= 10 and temperature <= 20) {
echo "Temperature is between 10 and 20" ;
}
swiftfun
4,039 PointsThis board is for Swift - iOS, not PHP