Logic: If/Else and Booleans
Up until now, all the programming has just been run once the computer gets to that line of code. If-statements allow you to tell the computer to only run a piece of code once a certain condition happens. In programming there are types like numbers or strings. There is another type which is called a Boolean. A boolean is a type that must be either true or false. You could just type in true or false and the boolean will either always run (if true) or never run (if false). You can also put in a variable that is related to a boolean. There are a number of different booleans that are listed below. You can also used the Logical Operators && (and) and || (or) to check multiple conditions at once. Project: Magic 8 Ball.
Â
![If/Else and Boolean code.](https://static.wixstatic.com/media/b86045_f8957583cb4d465ba8cfc833470658e6~mv2.png/v1/fill/w_602,h_840,al_c,q_90,enc_auto/b86045_f8957583cb4d465ba8cfc833470658e6~mv2.png)