You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jolon Faichney edited this page Feb 17, 2017
·
4 revisions
A boolean is a data type which has two possible values: true or false.
Most programming languages have a concept of booleans.
Apart from the direct values of true and false, comparison operators also result in a boolean value.
For example for our if statements we have been comparing numbers.
5 < 10 results in the boolean value true
12 < 10 results in the boolean value false
The if statement expects a boolean value:
if (boolean) {
}
For example the following if statement will always execute:
if (true) {
}
The for loop also requires a boolean for its condition. Note that we use a comparison operator:
for (var i = 0; i < 10; i++) {
}
The following for loop will loop forever:
for (var i = 0; true; i++) {
}
A for loop will only end when its condition becomes false, this for loop will never execute its body because it always checks the condition before executing the body: