CS101 Control Flow
Learn how to control the flow of code execution in Python.
StartKey Concepts
Review core concepts you need to learn to master this subject
Conditional Control
Control Flow
elif
Statement
Handling Exceptions in Python
or
Operator
Equal Operator ==
Not Equals Operator !=
Comparison Operators
Conditional Control
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
- 1How 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…
- 2If 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…
- 5Let’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…