pdf week 2 Flashcards
What do conditionals allow in programming?
Conditionals allow a program to make decisions based on certain conditions, like choosing a path based on user input
Give examples of when conditionals are useful.
When a user inputs wrong data (e.g., expecting an integer but receiving text).
When reaching the end of a file.
After a sufficient number of actions are performed (e.g., printing numbers from 1 to 10).
>
greater than
<
less than
> =
greater than or equal to
<=
less than or equal to
==
equals to
!=
not equal to
What is control flow?
Control flow refers to the order in which individual statements, instructions, or function calls are executed in a program.
How does elif improve the efficiency of conditional statements?
elif allows the program to skip subsequent checks once a true condition is found, reducing unnecessary evaluations.
Why use an else statement?
An else statement provides a default action when none of the preceding conditions are met, simplifying logic.
What does the or operator do?
The or operator allows the program to evaluate multiple conditions, executing the code block if at least one condition is true.
What does the and operator do?
The and operator requires all conditions to be true for the code block to execute.
What is short-circuit evaluation?
In short-circuit evaluation, if the first condition of an and or or statement determines the outcome, the second condition is not evaluated.
What are nested conditionals?
Nested conditionals are conditionals placed inside other conditionals, allowing for more complex decision-making.