โ† All Technology topics
Technology ยท Topic 19 of 59

If and Else Decisions

Programs make decisions with conditions: if something is true, do one thing, else do another. 'If it is raining, take an umbrella.'

๐Ÿ’ก Fun fact

Computers check conditions millions of times a second.

All about If and Else Decisions

Programs make decisions using conditions. An if statement checks whether something is true and runs a block of code if it is. An else statement runs different code if the condition is false. For example, if it is raining, take an umbrella; else, wear sunglasses.

Decisions let programs respond to what is happening. A game might check if a player has enough coins before buying an item, and a quiz app might check if an answer is right or wrong.

๐ŸŽฎ Try it yourself!

Loadingโ€ฆ

Real-life uses of If and Else Decisions

  • Checking whether a password is correct
  • Deciding which level to show in a game
  • Choosing a message based on a score

Frequently asked questions about If and Else Decisions

What is a condition?

A test that is either true or false, such as score is greater than 10.

What is else if?

A way to check several conditions in order, running the first one that is true.

Can you have an if without an else?

Yes. The else part is optional. If the condition is false, the program just skips the block.