4.5 Code block, conditions
In the previous video we saw different ways to use the "if" condition, I will show you some parts of the "if". In the previous video that we were able to do, we were able to use "if" conditions, but in this video we will make them clearer and more precise. So by modifying our "if" condition, we are going to replace "if (value = 11)" by "if (value less than 10)", we display the value... We can put something like "else" which means "sinon " in French, just to see what will happen, we will display "the value is not less than 10", we run our code and we see that our first process has been checked if the value is less than 10, the test not being validated, the code block of the first condition has not been executed so what happens is that the computer goes to the next step, if the first condition is not validated, it will then go to the "else" condition, if we change the condition "if (value greater than or equal to 10)" and we execute our code, we see that the "else" part is not executed because the condition is validated. We see that the "if" condition can be useful in several situations, but we can extend it even further! Let's put an "else if" which means "sinon si" (in French), by putting a condition inside, "else if (value=10)" and in output "value is equal to 10". So now we have two conditions, the first which checks if the value is greater than 10, then if the first condition is not validated we go to the second condition, which checks if the value is equal to 10, and if the second condition is not validated then we pass in the "else" which will display "invalid condition". Since the value is equal to 10 the condition that is going to be validated is the first one because, "value = 10" is in the first condition, we say "if ( value >= 10 )", we display the value. We see that the output indicates that the condition "if is greater than or equal to 10" is valid! In the next lesson, we will continue to use the "if" and then "else" condition, and we will perform some exercises to handle these conditions, see you soon!