Flow Of Control Flashcards
Logical operators or logical connectives
Not, and, or, ==
2 possible Boolean values, True or False
Logical equivalence
P == q
==
Will be True only when both have the same truth value. (Both True ir both false)
Logical “and”
P and q
True only when both are True
P and q
True only when p is true and q is true.
Logical “or”
P or q
True only when either one is True
!= means what?
Not equal
Logical negation
Not True
Not p
True when p is False, and False when p is True
If statements
Always begins with the keyword if.
Followed by Boolean expression called the if-condition
Followed by a colon (:)
If-statement header
Everything from the if statement to the :
Before_block If cond: True_block Else: False_block After_block
If/elif - statements
A generalized if-statement with more than one condition.
Elif = else if
If ..... : If_block Elif ... : Elif_block Else: Else_block
For-loops
A given block of code repeated some specified number of times.
For (loop variable) (keyword) (range):
For i in range(10):
While-loops
While-loop header
While (while loop condition)
The condition is boolean and always returns a True or False
If condition true, then executes while-loop body, if false executes what is after body.
First line is initialization statement ue i = 0
Incremental, i = i + 1
While-loop flow
Initializer_block
While cond:
Body_block
After_block
How do you exit a loop?
Break statement
Break # causes to jump out of the loop
Boolean logic
Boolean logic is all about manipulating so-called truth values.
Written True or False