Week 9 Part 1 Flashcards

1
Q

o Permits the program to make a decision, based on data and logic, resulting in different sequence structures to be executed.

A
  • Selection Structure, also called Decision Structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

o A selection structure starts with a ______ _________, and then takes of two paths

A

 Boolean expression

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

o Most programming languages have a selection structure, either __, __-____-____, and a ____ _________ (called switch in Java)

A

 If, if-then-else, and a case structure

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

o Obtains a user input, checks the input against one condition

A
  • Single-alternative selection structure
  • Would be able to determine if a user number is less, than 10, but nothing more.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Obtains a user input, checks the input against two conditions

A
  • Dual-alternative selection structure
  • Would be able to determine if a user number is more or less than 10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Obtains user inputs, checks the input against 1 decision, and then 2 nested decisions

A
  • Nested Selection Structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

o Using these combination operators, we can make more complicated decisions, such as determining if a number is within or outside of a range of values.

A

AND and OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • Testing Boundary Cases
A

o We test inputs that are just at, around, or beyond the minimum and maximum limits

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

o This must be remembered when using the NOT, AND & OR logical operators together

A

 Order of operations

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

o What is the bug in this code?
 if age <= 12 OR age >= 65 AND rating = “G” then
output “Discount applies”
Endif

A

 Add brackets around the or to separate it from the AND

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

o Can be used to flip logic which can simplify a selection structure

A
  • NOT operator (negative logic)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

o When can a NOT operator be useful?

A

 When you need to only take action if the condition is false
 it’s easier for another programmer to understand

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

 What’s better than this
 If number = 42
else
output “not 42”
endif

A

if number != 42
output “not 42”
endif

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

o Case structure is also known as ______ in Java

A

 Switch

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

o Case structure matches a value against ______ ______

A

single values

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

o When a case structure is useful

A

 If a decision needs to be made based on exact values matching a set of values

17
Q

o When a nested if-else is useful, and a case structure is sub-par

A

 When a decision needs to be made based on a range of values

18
Q

o Case structures “default” branch of logical is similar to

A

 Else