
🥑We use conditional statements all the time in real life. For example, suppose you go to your favorite restaurant and you ask for what you always eat there – Fish & Chips. The server lets you know that you can’t order that since they’ve run out of Fish and to please choose something else. So you order your second best choice – Pizza. 🥑Another example: If you do you’ve done your homework only then can you play game. Else you need to finish your homework first. 🥑In your code when you're making games you can control the way your program behaves/executes with conditional statements. If conditional statements can control the output of your program based on whether something isTrue
orFalse
. 🥑 Often used with comparison and equality operators 🥑There are 3 conditional statements that you can use: 1.If
2.Else
3.Else if
Useif
to specify a block of code to be executed, if a specified condition istrue
if (condition) {
//code to execute if the condition is true
}
Leave a Reply