Deck 4: Implementing Conditional Logic
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/49
Play
Full screen (f)
Deck 4: Implementing Conditional Logic
1
You can use conditional modifiers to group and control the execution of one or more statements, making your scripts easier to read and maintain.
False
2
A key point to understanding conditional programming logic is that it hinges on whether a condition is evaluated as true or false.
True
3
Unlike if modifiers, if expressions are limited to controlling the execution of a single statement at a time.
False
4
To save a few keystrokes, Ruby allows programmers to replace the when keyword with the : character when formulating a conditional statement using an if expression.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
5
The if modifier is attached to the end of a Ruby statement in order to conditionally control its execution.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
6
Conditional expressions provide the ability to append a conditional check to the beginning of Ruby statements in order to control the conditional execution of the statement.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
7
The if expression is a conditional evaluation appended to the end of Ruby statements to conditionally control the execution of the statement.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
8
The unless modifier is the logical opposite of the if modifier.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
9
else is an optional keyword that permits the execution of an alternate set of statements in the event a tested condition evaluates as false.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
10
The unless expression is used to create complex conditional evaluations spread out over multiple lines that perform the opposite type of evaluation as an if expression.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
11
The exit method is provided by the kernel class. It forces the immediate termination of a Ruby script.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
12
Using Ruby, you can create scripts that consist of a series of statements that are executed in sequential order. However, these scripts are often not suited to complex tasks.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
13
The Case statement is a conditional evaluation that performs a series of conditional tests, each of which is compared to a single value.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
14
Flowcharts provide a visual representation of the overall logic involved in creating some or all of a computer program or script.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
15
The unless modifier is a conditional evaluation appended to the end of Ruby statements that performs the opposite type of evaluation as the if modifier.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
16
The elsif keyword permits the evaluation of additional conditional tests when working with an if statement code block.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
17
Conditional Logic describes the process of executing sets of code statements based on the whether or not a tested condition proves true.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
18
The Ternary Operator is an operator that facilitates the inclusion of a conditional expression within another statement
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
19
You can modify an if modifier to execute one or more statements in the event the test condition evaluates as being false. To accomplish this, you need to add the optional else keyword.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
20
The if modifier is used to create complex conditional evaluations spread out over multiple lines.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
21
Nesting works just as effectively with unless expressions as it does with if expressions.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
22
Both the = and the == operators can be used to evaluate two expressions or value in order to determine if they are equal.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
23
Flowcharts are often used in large projects in order to ____.
A) Coordinate the efforts of multiple programmers working on the same project.
B) To clearly delineate different parts of a program or script.
C) To ensure that a programmer has an understanding of how the part of the project he is assigned fits into the overall scheme.
D) All of the above
A) Coordinate the efforts of multiple programmers working on the same project.
B) To clearly delineate different parts of a program or script.
C) To ensure that a programmer has an understanding of how the part of the project he is assigned fits into the overall scheme.
D) All of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
24
To determine if two values are not equal, which comparison operator should be used?
A) ==
B) !=
C) >=
D) !
A) ==
B) !=
C) >=
D) !
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
25
The unless expression is the polar opposite of the if expression.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
26
What happens if none of the when statements in a case code block match the value of the expression that is evaluated?
A) The statements belonging to the else statement (if present) are executed
B) The last when statements belonging to the last when statement is executed
C) All of the statements belonging to the when statements are executed
D) None of the above
A) The statements belonging to the else statement (if present) are executed
B) The last when statements belonging to the last when statement is executed
C) All of the statements belonging to the when statements are executed
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is true regarding case code blocks?
A) If more than one expression evaluates as true, both of its associated statements are executed
B) If more than one expression evaluates as true, the last matching expression is evaluated
C) The first expression that evaluates as true is executed and the rest of the statements are skipped
D) None of the above
A) If more than one expression evaluates as true, both of its associated statements are executed
B) If more than one expression evaluates as true, the last matching expression is evaluated
C) The first expression that evaluates as true is executed and the rest of the statements are skipped
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
28
To determine if one value is greater than or equal to another, which comparison operator should be used?
A) ==
B) >=
C) ==
D) !=
A) ==
B) >=
C) ==
D) !=
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
29
In most cases, it takes ____ lines of code to set up a case block when compared to an if expression that contains multiple elseif keywords.
A) More
B) Fewer
C) the same number of
D) None of the above
A) More
B) Fewer
C) the same number of
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
30
Ruby provides access to a number of conditional expressions, modifiers, and logical operators that can be used to ____.
A) Compare different values
B) Control the logical execution of different script statements
C) Create Ruby scripts capable of altering their execution based on the data that they are presented with
D) All of the above.
A) Compare different values
B) Control the logical execution of different script statements
C) Create Ruby scripts capable of altering their execution based on the data that they are presented with
D) All of the above.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
31
Like other modern programming languages, Ruby provides programmers with access to a range of comparison operators, not including ____.
A) ==
B) !=
C) >=
D) =
A) ==
B) !=
C) >=
D) =
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following is the ternary operator?
A) #
B) #!
C) ?:
D) None of the above
A) #
B) #!
C) ?:
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
33
The between? method can be used to perform which of the following tasks?
A) Returns a value or true or false depending on whether a number equals a specified value
B) Returns a value of true or false depending on whether or not a number is within a specified range
C) Returns a value of true or false depending on whether or not a value is numeric
D) None of the above
A) Returns a value or true or false depending on whether a number equals a specified value
B) Returns a value of true or false depending on whether or not a number is within a specified range
C) Returns a value of true or false depending on whether or not a value is numeric
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
34
The advantages of appending conditional modifiers to the end of script statements include ____.
A) It helps in the development of compact statements
B) It can help reduce the overall size of script files
C) It provides fine tuned control over the execution of individual statements
D) All of the above
A) It helps in the development of compact statements
B) It can help reduce the overall size of script files
C) It provides fine tuned control over the execution of individual statements
D) All of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
35
An if statement code block begins with the if keyword and ends with what keyword?
A) end
B) exit
C) endif
D) None of the above
A) end
B) exit
C) endif
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
36
The case block provides programmers with the ability to ____.
A) Compare a series of expressions against a single expression
B) Compare a single expression against another expression
C) Compare numeric values but not string values
D) None of the above
A) Compare a series of expressions against a single expression
B) Compare a single expression against another expression
C) Compare numeric values but not string values
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following is not true about flowcharts?
A) A flowchart is a tool used to graphically represent some or all of a script's logical flow.
B) Flowcharts are created by programmers to outline the overall design of the logic involved in a computer program or script prior to beginning work on it.
C) Flowcharts provide a statement by statement outline of all of the programming logic that makes up a computer program or script.
D) None of the above
A) A flowchart is a tool used to graphically represent some or all of a script's logical flow.
B) Flowcharts are created by programmers to outline the overall design of the logic involved in a computer program or script prior to beginning work on it.
C) Flowcharts provide a statement by statement outline of all of the programming logic that makes up a computer program or script.
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
38
The case block evaluates an expression that is compared to values associated with one or more when statements.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
39
Ruby provides programmers with access to several ways of applying conditional logic, including all of the following except ____.
A) The switch modifier
B) The unless modifier
C) The Case statement
D) The if expression
A) The switch modifier
B) The unless modifier
C) The Case statement
D) The if expression
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
40
A case block is well suited to situations where you need to compare a single value to a whole range of possible matches.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
41
The following example is an example of what type of conditional evaluation? print "Enter your age and press Enter: " answer = STDIN.gets answer.chop! puts "You must be 18 or older to play this game!" if answer.to_i
A) if expression
B) Ternary operator
C) if modifier
D) None of the above
A) if expression
B) Ternary operator
C) if modifier
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
42
Ruby supports the use of a number of logical or Boolean operators, including which of the following?
A) and
B) &&
C) ||
D) All of the above
A) and
B) &&
C) ||
D) All of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
43
Some situations require a more complicated analysis than can be accomplished using an single conditional modifier or expression. One way of performing more complex conditional testing is through a processing called ____.
A) Nesting
B) Concatenation
C) Ternary analysis
D) None of the above
A) Nesting
B) Concatenation
C) Ternary analysis
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following is true when it comes to nesting conditional statements?
A) Ruby limits nesting to a maximum of three levels
B) Nesting is available only when working with if expressions
C) There is no limitation as to how deeply you can next conditional statements
D) None of the above
A) Ruby limits nesting to a maximum of three levels
B) Nesting is available only when working with if expressions
C) There is no limitation as to how deeply you can next conditional statements
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following is a limitation of the case blocks?
A) They are limited to the analysis of numeric data
B) They generate an error if no when statements match the tested expression
C) Unlike the if expression, case blocks do not allow you to substitute the when keyword with the : character
D) None of the above
A) They are limited to the analysis of numeric data
B) They generate an error if no when statements match the tested expression
C) Unlike the if expression, case blocks do not allow you to substitute the when keyword with the : character
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following logical (Boolean) operators is most similar to the && operator?
A) and
B) ||
C) !
D) None of the above
A) and
B) ||
C) !
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following statements best describes the Ternary operator?
A) It compares a series of values against a single value
B) It is attached to the end of a statement in order to conditional control the statements execution.
C) It is used nest one of more conditional statements.
D) None of the above
A) It compares a series of values against a single value
B) It is attached to the end of a statement in order to conditional control the statements execution.
C) It is used nest one of more conditional statements.
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
48
Advantages of the if and unless expressions include all of the following except?
A) They allow you to control the execution of one or more code statements
B) They can help improve the organization of scripts and make them easier to read and maintain
C) They can be used to work with any type of value supported by Ruby
D) None of the above
A) They allow you to control the execution of one or more code statements
B) They can help improve the organization of scripts and make them easier to read and maintain
C) They can be used to work with any type of value supported by Ruby
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
49
What is the difference between the or and the || operators?
A) There is no difference between these two operators
B) The || operator has a higher level of precedence
C) The or operator has a higher level of precedence
D) None of the above
A) There is no difference between these two operators
B) The || operator has a higher level of precedence
C) The or operator has a higher level of precedence
D) None of the above
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck