If you're seeing this message, it means we're having trouble loading external resources on our website.

# 复习：逻辑和 if 语句

if 语句 告诉程序执行一段代码，如果某一个条件成立的话。在以下的代码中，我们只有在 `x` 大于 0 时才输出一段信息：
``````var x = 5;

if (x > 0) {
text('x is a positive number!', 200, 200);
}``````

`x > 0` 是所谓的 条件表达式 - 意思就是一个判断`true`（成立）或`false` （不成立）的表达式。当一个值是 `true``false` 时，我们就叫它 boolean 值（而不是数值或字符串）。例如，我们可以直接显示这个条件表达式：
``text(x > 0, 200, 200); // 显示 "true"``

``````var isPositive = x > 0;
text(isPositive, 200, 200);``````

``var myAge = 28;``

===严格相等`myAge === 28`
!==严格不相等`myAge !== 29``28 !== 29`
>大于`myAge > 25``28 > 25`
>=大于等于`myAge >= 28``28 >= 28`
<小于`myAge < 30``28 < 30`
<=小于等于`myAge <= 28``28 <= 28`

``````var x = 2 + 2; // 赋值为 4

if (x === 4) { // 问 "这个是否等于 4?"
text("yep, 2 + 2 = 4!", 200, 200);
}``````

``````var degreesOutside = 70;
var numberOfClouds = 50;
if (degreesOutside > 70 && numberOfClouds < 5) {
text("Wear sun screen!", 200, 200);
}``````

``````rect(100, 50, 100, 100);

mousePressed = function() {
if (mouseX > 100 && mouseX < 200 && mouseY > 50 && mouseY < 150) {
text("You pressed it!", 80, 75);
}
};``````

``````var degreesOutside = 70;
var numberOfClouds = 50;
if (degreesOutside > 70 || numberOfClouds < 5) {
text("Wear sun screen if it's hot outside or there aren't many clouds!", 200, 200);
}``````

``````var myAge = 28;
if ((myAge >= 0 && myAge < 3)  || myAge > 90) {
println('You\'re not quite in your peak.');
}``````

``````var age = 28;
if (age > 16) {
println('Yay, you can drive!');
} else {
println('Sorry, but you have ' + (16 - age) + ' years until you can drive.');
}``````

``````var age = 20;
if (age >= 35) {
println('You can vote AND hold any place in government!');
} else if (age >= 30) {
println('You can vote AND run for the Senate!');
} else if (age >= 18) {
println('You can vote!');
} else {
println('You have no voice in government!');
}``````