Key Concepts

Review core concepts you need to learn to master this subject

Conditional Control

Conditional statements or conditional control structures allow a program to have different behaviors depending on certain conditions being met.

Intuitively, this mimics the way humans make simple decisions and act upon them. For example, reasoning about whether to go outside might look like:

  • Condition: Is it raining outside?
    • If it is raining outside, then bring an umbrella.
    • Otherwise, do not bring an umbrella.

We could keep adding clauses to make our reasoning more sophisticated, such as “If it is sunny, then wear sunscreen”.

Control Flow
Lesson 1 of 2
  1. 1
    How do computers make decisions? Here are a few examples: * Web surfing: Open the browser, load the text, load the images. * Social media: If the user’s profile is private, hide their posts. Other…
  2. 2
    If the user’s profile is private, hide their posts. Otherwise, make them visible. Computers can run instructions on their own, leaving us to work on more interesting and creative problems. But c…
  3. 3
    Repeat a sound four times a measure. Computers are good at repetitive tasks: they exactly follow instructions and perform them quickly. But if the programmer has to write the same instructions f…
  4. 4
    Collect shipping and email address. Reject a purchase if either is incorrect. Errors, or exceptions, happen all the time in programming. You can’t escape them. But you can handle them gracefully…
  5. 5
    Let’s recreate the conditional control structure using JavaScript! (The one about social media posts, remember?) ![Diagram of conditional control structure](https://content.codecademy.com/progra…
  6. 6
    Well done! Control flow is a fundamental concept in programming, and learning the basics will serve you wherever your path leads, regardless of language or domain. In review: - Control flow is t…