Week 3 - Selection & Iteration Flashcards

1
Q

Selection

A

Blocks of code having decisions or branches, where a variety of paths can be taken.

(Like in a flowchart with diamonds)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Iteration

A

A kind of block where instructions are repeated a number of times making use of loops.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to represent in C if values are the same?

A

a == b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to represent in C if values are different?

A

a != b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to represent in Pascal if values are the same?

A

a = b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to represent in Pascal if values are not the same?

A

a <> b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Pre-Test Loop

A

While the condition is true, it will continue to loop until met.

A pretest loop tests its condition before each iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Post-Test Loop

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When do we use post-test loops?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Break Statement

A

Used to jump out of a loop or if statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the different types of values in Ruby?

A

Numerics, Integers & Arrays are the main ones

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the syntax of a for loop?

A

count = 0

for count in 0..4 do

(FOR the VARIABLE IN that RANGE, DO this piece of code)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the difference between “..” and “…” range?

A

.. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly