Now let's have a look at a few mistakes often made by beginner programmers when it comes to writing conditional branches. The first trap that awaits you is that the equality test is written with two equal symbols, like here, and not a unique equal symbol, which is used for assignment. This code is therefore incorrect, as there's only one equal symbol, the correct version is of course : if (a == 1), and this code which is incorrect is simply not allowed by the Java compiler. Here's a second mistake example, do you see the problem ? In fact, there shouldn't be any semicolon here and if we execute this code, it will be accepted by the compiler and the message "a vaut 1" will get printed whatever the value of a is, so it's a little mysterious, but to understand why you must know that the semicolon is considered as an instruction, an instruction that does nothing. I could have written this code in this way, which is easier to interpret, because the semicolon, this emtpy instruction, is considered inside the conditional branch, but this instruction is considered outside the conditional branch. If a has the value 1, we enter the conditional branch, execute the empty instruction, that is, do nothing, and whatever the value of a is, skip to this instruction and print the message "a vaut 11". Note that if we had used curly braces when there's only one instruction in the conditional branch, the mistake that we have just seen would have had less chance of happening. It is therefore a good practice to systematically use curly braces, even when there's only one instruction in the block. A third mistake is, precisely, forgetting the curly braces when they are necessary, like in this code. Having these lines indented, that is, having them shifted a but to the right, isn't sufficient for them to be inside the conditional branch, unlike other languages. In your opinion, what happens when I try to compile this code ? Well, the compiler will print this error message which tells me that there's an else without the key-word if. So why ? Because in fact, I could have written this code this way, the first instruction, which is the print instruction is indeed inside the conditional branch, but this second instruction isn't, it is after the conditional branch and when the compiler comes upon this else, it is already outside the conditional branch which is here and this else is therefore not attached to an if instruction. That's why it generates this error message. Now let's take three quizzes. First of all, what does this code print when it is executed and when the user inputs the value 1 for the variable n and 2 for the variable p. So in your opinion, what's the correct answer ? The correct answer is the answer C and we are going to see why. If you think you've understood, you can go directly to the next quiz. Let me remind you that in order for a condition which uses the AND logical operator, written like this, to be true, the two conditions must be true. In order for a condition which uses the OR logical operator, written like this, to be true, it is sufficient for one of the two conditions to be true. The user inputs the values 1 for the variable n and 2 for the variable p. This condition "n strictly less than p" is true, as n is equal to 1 and p is equal to 2 and that 1 is strictly less than 2. This expression has the value two times n, that is, two times 1, which is two, p has the value 2, therefore this entire condition is true, as 2 is indeed greater than or equal to 2. This condition is therefore true, so we enter the conditional branch and execute this instruction which simply prints 1, 1. We then move on to this conditional branch. This condition is still true, it's the same as the one we had previously, as it's an OR here, I don't have to consider the value of this condition, because I already know that this entire condition is true. We therefore print 2 here. We then move on to this conditional branch. This condition, which is the same as above, is still true, so we enter this conditional branch and test this new condition. This expression has the value two times n, that is, 2. p has the value 2, so this condition is true, as 2 is greater than or equal to 2, we execute this part of the conditional branch, so we print 3, skip this part, we arrive at the end of the conditional branch here, we move on and simply print a newline, Second exercise, same code, but this time the user inputs the values 1 for the variable n and 3 for the variable p. So, in your opinion, what is the correct answer ? The correct answer is the answer B, let's see why. This time n has the value 1, p has the value 3, this condition is true as 1 is strictly less than 3. This expression has the value 2 times 1, that is 2, p has the value 3, so this condition is false, as 2 isn't greater than or equal to 3. As it's an AND here, this condition is false and we go directly to the next instruction which is also a conditional branch. This condition is the same as before, it is still true. As it's an OR here, I know that this entire condition is true. We therefore enter the conditional branch, print a 2, and move on to this conditional branch. This condition is the same as before, it is always true, so we enter the conditional branch. This condition is false, like before, it's the same as this one. We execute the second part of the conditional branch, that is, be print 4, move on to this instruction which simply prints a newline. This time, the values entered by the user are 2 for n and 1 for p. In your opinion, what is the correct answer ? The correct answer is the answer A. For this last exercise, n has the value 2 and p has the value 1. This time, this condition is therefore false, as 2 isn't strictly less than 1. As it is an AND here, I don't have to evaluate this condition, I already know that this entire condition is necessarily false. I therefore move on to this conditional branch. This condition is, well, the same as before, I had said it was false, but here it's an OR, so I have to evaluate this expression, this condition, 2 times n is 4, p has the value 1, and because 4 is greater than or equal to 1, this condition is true. As it's an OR, this condition is true, so we execute this instruction, that is, print a 2. We then move on to here. This condition is false, it's once again the same as before, so we skip this conditional branch to reach this stage of the program which simply prints a newline. Now let's turn to the boolean type, which is the type of the conditions. This type will let us declare variables which will contain the condition's value. A variable of type boolean is often simply called a a boolean and can only contain two possible value, either true, or false, or more exactly in Java, we'll use the literal values true and false, as expressed in English. In this example, I begin by declaring two variables a and b of type int, a is initialized to 1, b is initialized to 2. This instruction is a boolean variable declaration, this variable is called test1, which will be, indeed, of type boolean. Like with any variable, I can represent it with a box. This variable is initialized to the value of the condition a equal b, a has the value 1, b has the value 2, so this condition is false and test1 will be initialized to false. This following instruction declares a second variable of type boolean, this time called test2, which will be initialized to the value of the condition a strictly less than b. As a has the value 1 and b has the value 2, this condition is true. Therefore, test2 will be initialized to true. Some students don't have any problems with booleans, others sometimes have a mental block. So, remember that a variable of type boolean is a variable like another, that is, you can represent it as a box. It turns out this box can only contain two possible values, either true or false. It also turns out that we can use logical operators between variables of type bool and that we can use these variables like conditions, for example inside a conditional branch, and that's what we're going to see in this example. As in the previous example, I begin by declaring a variable a of type int initialized to 1, a variable b also of type int, initialized to 2. In the following instruction, I this time declare a variable of type boolean which is called c and which is initialized to the value true. In the following instruction I declare a boolean which is called d, and which is initialized to the value of the condition a equal b. a has the value 1, b has the value 2, the condition is false, it therefore has the value false. Thus d is initialized to false. In the following instruction, I declare a variable of type boolean which is called e and which is initialized to the value of the condition. d has the value false. This condition, a less than b, is true, it therefore has the value true. As the logical operator here is an OR, this entire condition is true and it has the value true. So e is initialized to true. We now move on to this conditional branch which has as condition the value of the boolean variable called e, which is true, so this condition is true, and we enter the conditional branch to execute this instruction and print the message "e vaut true" (TN which means "e has the value true"). Voilà ! That's all for the moment concerning booleans, but be aware that they are helpful in many situations and we'll encounter them in many examples.