Week 3 - Selection & Iteration Flashcards
Selection
Blocks of code having decisions or branches, where a variety of paths can be taken.
(Like in a flowchart with diamonds)
Iteration
A kind of block where instructions are repeated a number of times making use of loops.
How to represent in C if values are the same?
a == b
How to represent in C if values are different?
a != b
How to represent in Pascal if values are the same?
a = b
How to represent in Pascal if values are not the same?
a <> b
Pre-Test Loop
While the condition is true, it will continue to loop until met.
A pretest loop tests its condition before each iteration.
Post-Test Loop
The code will end until the condition is met.
A post test loop tests its condition after each iteration.
A post test loop will always execute at least once.
When do we use post-test loops?
If you want the code in the body to run at least once.
Eg: If the file has any data in it, if the network has any data available and what the user wants to do next.
Break Statement
Used to jump out of a loop or if statement.
What are the different types of values in Ruby?
Numerics, Integers & Arrays are the main ones
What is the syntax of a for loop?
count = 0
for count in 0..4 do
(FOR the VARIABLE IN that RANGE, DO this piece of code)
What’s the difference between “..” and “…” range?
.. is inclusive of the last value. Eg: 1..4 = 1, 2, 3, 4
.. is not exclusive of the last value. Eg: 1…4 = 1, 2, 3