T7 - Sequence/Selection and Iteration Flashcards
Three operators used in Boolean expressions?
AND, OR, NOT
3 basic control structures used in programming:
Sequence, selection and iteration
Sequence:
The statements are executed
one by one in the order they are written
Selection -
next statement to be executed depends on whether the condition being tested is True or False
selection eg
Eg if statements (allow different branches to be executed based on the result of a Boolean expression)
==
equal to
!=
not equal to
>
greater than
greater than or equal to
> =
<
lesser than
lesser than or equal to
<=
AND
return as true if both conditions are true
OR
returns as true as long as one is true
NOT
returns the opposite value
Random numbers:
in Python,
import random to access library (numbers)
or
random.randint(0, 100) to generate range
random numbers - Pseudocode
random(0, 100)
To generate a decimal number
use range -100.0 and 100.0,
Iteration
- repetition of a section of code
iteration eg
Eg:
for … next
while … endwhile
do … until (not in python)
For loops -
when you want to execute the loop a specified number of times
Use i in rage
While loops -
when you want to execute the loop while a certain condition is true.
infinite loop -
If a loop continues forever and there is no way to exit it
while loop is tested when
the condition is tested at the beginning of the loop
do … until loops:
when you want to execute the loop until a certain condition is True
do … until loops: tested when
The condition is tested at the end of the loop