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 trialMiguel Leon
1,720 PointsWhat is a Boolean ?
I already finished swift basics but i still can't quite understand the function of a boolean.
2 Answers
Jhoan Arango
14,575 PointsThe concept of a bool is pretty simple, think of it as a condition that is true or false.
For example.
/*
Are you human ? There are two posible answers to the question ( true or false )
therefore this can be consider a boolean. Lets see it in code.
*/
var human = true
if human == true {
println("Yes this is true")
} else {
println("No this is false")
}
// This will print “Yes this is true” because the variable human
// was declared with the value "true"
/*
You can read that as If human is true, then print “Yes this is true”, if it’s false, print “No this is false” So the condition of something being true or false is a boolean. It only has those two answers.
Hope you understand.
Austin Liu
3,326 PointsA boolean is a value that either responds in 'true' or 'false', or in simpler terms, 'yes' or 'no'. Booleans can be used in asking if, suppose if a user is connected to the internet, or if they like cheese, or something along those lines. Hope this helped!
David Richardson
10,213 PointsDavid Richardson
10,213 PointsBoolean is a data type that only has 2 possible values, either true or false (1 or 0)