Deck 6: Control Statements: Part 2
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
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/66
Play
Full screen (f)
Deck 6: Control Statements: Part 2
1
Which of the following is not a control statement in C#
A) do…while
A) do…while
B
Essentials of Counter-Controlled Repetition
Essentials of Counter-Controlled Repetition
2
The for repetition statement handles the details of counter-controlled repeti
tion.
tion.
True
3
Consider the following two C# code segments:
Segment 1 Segment 2
Int i = 0;
For (int i=0;i < = 20;++i)
While (i < 20) {
{ Console.WriteLine (i);
++i; }
Console.WriteLine (i);
}
Which of the following statements is true
A) The output from these segments is not the same.
B) The scope of the control variable i is different for the two segments.
C) Both (a) and (b) are true.
D) Neither (a) nor (b) is true.
Segment 1 Segment 2
Int i = 0;
For (int i=0;i < = 20;++i)
While (i < 20) {
{ Console.WriteLine (i);
++i; }
Console.WriteLine (i);
}
Which of the following statements is true
A) The output from these segments is not the same.
B) The scope of the control variable i is different for the two segments.
C) Both (a) and (b) are true.
D) Neither (a) nor (b) is true.
C
4
The first line of the for statement is sometimes called the:
A) for statement header
B) increment header
C) repetition header
D) None of the above.
A) for statement header
B) increment header
C) repetition header
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following for-loop control headers results in equivalent numbers of iterations:
1)for (int q = 1;q < = 100;++q)
2)for (int q = 100;q >= 0;--q)
3)for (int q = 99;q > 0;q -= 9)
4)for (int q = 990;q > 0;q -= 90)
A) 1) and 2)
B) 3) and 4)
C) 1) and 2) have equivalent iterations and 3 and 4 have equivalent iterations
D) None of the loops have equivalent iterations
1)for (int q = 1;q < = 100;++q)
2)for (int q = 100;q >= 0;--q)
3)for (int q = 99;q > 0;q -= 9)
4)for (int q = 990;q > 0;q -= 90)
A) 1) and 2)
B) 3) and 4)
C) 1) and 2) have equivalent iterations and 3 and 4 have equivalent iterations
D) None of the loops have equivalent iterations
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
6
Modifying the control variable of a for statement in the body can cause errors.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following for headers is syntactically incorrect
A) for (int i = 1; i < 10;)
B) for (; i == 3;)
C) for (i == 3)
D) None of the above.
A) for (int i = 1; i < 10;)
B) for (; i == 3;)
C) for (i == 3)
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
8
If a while condition is never true,the body will never execute.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
9
The header for (int i = 0;i < = 10;++i)will cause i to be incremented:
A) before the body begins execution
B) after the body begins to execute, but before it finishes
C) after the entire body executes
D) None of the above.
A) before the body begins execution
B) after the body begins to execute, but before it finishes
C) after the entire body executes
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
10
Only one control variable may be initialized,incremented or decremented in a for statement header.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
11
A while statement automatically increments a variable that a programmer specifies.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
12
A common logic error known as a(n)occurs when the programmer incor
Rectly specifies a conditional operator,such as < instead of < =.
A) fatal error
B) off-by-one error
C) syntax error
D) None of the above.
Rectly specifies a conditional operator,such as < instead of < =.
A) fatal error
B) off-by-one error
C) syntax error
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
13
Counting loops should be controlled with whatever data type most closely reflects the operations taking place,whether that is an int,float or double.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
14
A variable used as a counter should be initialized when it's declared.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
15
Counting loops should be controlled with values.
A) double
B) int
C) char
D) None of the above.
A) double
B) int
C) char
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
16
Counter-controlled repetition requires only a control variable,an initial value for the control variable and an increment or decrement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
17
The initialization expression,condition and increment expression in a for statement's header must be separated with commas.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
18
A control variable that's declared in a for statement header is not accessible outside of the body of the for statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
19
for statements cannot be represented as while statements.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
20
Unary operators (such as ++)cannot be used in conditions.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following statements is false
A) C# does not include an exponentiation operator.
B) The expression
Math.Pow(x, y)
Calculates the value of x raised to the yth power.
C) C# will implicitly convert a double to a decimal, or vice versa.
D) In loops, avoid calculations for which the result never changes-such calculations should typically be placed before the loop. Optimizing compilers will typically do this for you.
A) C# does not include an exponentiation operator.
B) The expression
Math.Pow(x, y)
Calculates the value of x raised to the yth power.
C) C# will implicitly convert a double to a decimal, or vice versa.
D) In loops, avoid calculations for which the result never changes-such calculations should typically be placed before the loop. Optimizing compilers will typically do this for you.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
22
Braces are normally included with do…while statements even when unnec
essary to avoid confusion with the while statement.
essary to avoid confusion with the while statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
23
The loop body of a do…while statement always executes __________.
A)zero times
B)at least once
C)more than once
D)undeterminable
A)zero times
B)at least once
C)more than once
D)undeterminable
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
24
A default case must be provided for every switch statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
25
Some compilers will automatically remove from loops body statements that do not need to be executed multiple times through a process known as
A) classification
B) optimization
C) interpretation
D) None of the above.
A) classification
B) optimization
C) interpretation
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
26
The C# operator ^ can be used for exponentiation.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is equivalent to this code segment
Segment: int total = 0;
For (int i = 0;i < = 20;i += 2)
{
Total += i;
}
A) int total = 0;
B) int total = 0;
C) int total = 0;
D) int total = 0;
Segment: int total = 0;
For (int i = 0;i < = 20;i += 2)
{
Total += i;
}
A) int total = 0;
B) int total = 0;
C) int total = 0;
D) int total = 0;
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
28
A case can be labeled as to execute in the event that none of the pro
Vided cases are equivalent to the controlling expression.
A) general
B) default
C) case *
D) None of the above.
Vided cases are equivalent to the controlling expression.
A) general
B) default
C) case *
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
29
The do…while repetition statement tests the condition the body of the loop executes.
A) before
B) while
C) after
D) None of the above.
A) before
B) while
C) after
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
30
What occurs when an empty case matches the controlling expression
A) fall through
B) syntax error
C) infinite loop
D) None of the above.
A) fall through
B) syntax error
C) infinite loop
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
31
A loop that counts down from 10 to 1 using control variable counter should use the loop-continuation condition counter < = 1.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
32
It's possible to specify that a constant is of type decimal by appending the letter m to the constant.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
33
A case that consists of multiple lines must be enclosed in braces.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
34
The initialization and increment expressions in a for statement can be comma-separated lists that enable you to use ________.
A) multiple initialization expressions
B) multiple increment expressions
C) multiple initialization expressions and/or multiple increment expressions
D) neither multiple initialization expressions nor multiple increment expressions
A) multiple initialization expressions
B) multiple increment expressions
C) multiple initialization expressions and/or multiple increment expressions
D) neither multiple initialization expressions nor multiple increment expressions
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
35
Many classes provide methods to perform common tasks that do not require specific objects-they must be called using a class name.Such methods are called ________ methods.
A) classwide
B) dot (.)
C) console
D) static
A) classwide
B) dot (.)
C) console
D) static
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following statements is false
A) When a decimal variable is initialized to an int value, the int value must be cast to decimal.
B) C# treats whole-number literals like 7 and 1000 as type int.
C) Unlike double values, int values can be assigned to decimal variables.
D) C# treats numeric literals like 0.05 as type double.
A) When a decimal variable is initialized to an int value, the int value must be cast to decimal.
B) C# treats whole-number literals like 7 and 1000 as type int.
C) Unlike double values, int values can be assigned to decimal variables.
D) C# treats numeric literals like 0.05 as type double.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
37
Compressing statements before and in a for statement into the for header can reduce the readability of a program
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
38
Infinite loops are caused when the loop-continuation condition in a while,for or do…while statement never becomes true.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
39
What is the Windows key sequence for typing the end-of-file indicator in Command Prompt window
A) < Alt > z
B) < Ctrl > z
C) < Windows >z
D) < Shift >z
A) < Alt > z
B) < Ctrl > z
C) < Windows >z
D) < Shift >z
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following will count down from 10 to 1 correctly
A) for (int j = 10; j < = 1; ++j)
B) for (int j = 1; j < = 10; ++j)
C) for (int j = 10; j > 1; --j)
D) for (int j = 10; j >= 1; --j)
A) for (int j = 10; j < = 1; ++j)
B) for (int j = 1; j < = 10; ++j)
C) for (int j = 10; j > 1; --j)
D) for (int j = 10; j >= 1; --j)
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
41
Only the statements for one case can be executed in any one execution of a switch statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
42
The continue statement is used to undo the effects of the break statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
43
A case with no statements is called an empty case,and requires only the break statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
44
The statement,when executed in a while loop,skips the remaining statements in the body of the statement and begins the next iteration of the loop.
A) continue
B) break
C) next
D) None of the above.
A) continue
B) break
C) next
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
45
The statement,when executed in a for loop,will terminate the loop.
A) continue
B) break
C) next
D) None of the above.
A) continue
B) break
C) next
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
46
The logical exclusive OR operator is true if it at least one of its operands is true.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
47
The break statement terminates a program.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
48
The second operand of an && operator will not be evaluated if the first operand evaluates to true.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
49
The effects of break and continue statements can be achieved by struc
tured programming techniques.
tured programming techniques.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
50
The && operator has higher precedence than the || operator.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
51
Which is equivalent to if (!(grade == sentinelValue))
A) if (grade !== sentinelValue)
B)if (grade != sentinelValue)
C) if (grade == sentinelValue)
D) if (grade !== sentinelValue)
A) if (grade !== sentinelValue)
B)if (grade != sentinelValue)
C) if (grade == sentinelValue)
D) if (grade !== sentinelValue)
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
52
Which of the following operators ensures that at least one out of multiple conditions is true
A) ||
B) &&
C) ==
D) ^
A) ||
B) &&
C) ==
D) ^
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
53
Suppose variable gender is MALE and age equals 60,how is the expression
(gender == FEMALE)&& (age >= 65)
Evaluated
A) The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
B) The condition (age >= 65) is evaluated first and the evaluation stops immediately.
C) Both conditions are evaluated, from left to right.
D) Both conditions are evaluated, from right to left.
(gender == FEMALE)&& (age >= 65)
Evaluated
A) The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
B) The condition (age >= 65) is evaluated first and the evaluation stops immediately.
C) Both conditions are evaluated, from left to right.
D) Both conditions are evaluated, from right to left.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
54
Which case of the following would warrant using the boolean logical inclusive OR (|)rather than the conditional OR (||)
A) Testing if two conditions are both true.
B) Testing if at least one of two conditions is true.
C) Testing if at least one of two conditions is true when the right operand has a required side effect.
D) Testing if at least one of two conditions is true when the left operand has a required side effect.
A) Testing if two conditions are both true.
B) Testing if at least one of two conditions is true.
C) Testing if at least one of two conditions is true when the right operand has a required side effect.
D) Testing if at least one of two conditions is true when the left operand has a required side effect.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
55
Which of the following statements about the break statement is false
A) The break statement is used to exit a repetition statement early and continue execution after the loop.
B) A break statement can only break out of an immediately enclosing while, for, do…while or switch statement.
C) The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
D) Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.
A) The break statement is used to exit a repetition statement early and continue execution after the loop.
B) A break statement can only break out of an immediately enclosing while, for, do…while or switch statement.
C) The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
D) Common uses of the break statement are to escape early from a loop or to skip the remainder of a switch.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
56
Assuming a is a bool with a value of false,which of the following eval
Uates to true
A) !(!a)
B) a
C) !a
D) None of the above.
Uates to true
A) !(!a)
B) a
C) !a
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
57
Short-circuit evaluation is a performance feature related to the evaluation of conditional AND and conditional OR expressions.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
58
Which of the following statements about the continue statement is true
A) The continue statement is used to exit a repetition statement early and continue execution after the loop.
B) The continue statement is used to continue after a switch statement.
C) The continue statement does not alter the flow of control.
D) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do…while statement.
A) The continue statement is used to exit a repetition statement early and continue execution after the loop.
B) The continue statement is used to continue after a switch statement.
C) The continue statement does not alter the flow of control.
D) A continue statement proceeds with the next iteration of the immediately enclosing while, for, do…while statement.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
59
Consider the code segment below.
If (gender == 1)
{
If (age >= 65)
{
++seniorFemales;
}
}
This segment is equivalent to which of the following
A) if (gender == 1 || age >= 65) {
B) if (gender == 1 && age >= 65)
C) if (gender == 1 AND age >= 65)
D) if (gender == 1 OR age >= 65)
If (gender == 1)
{
If (age >= 65)
{
++seniorFemales;
}
}
This segment is equivalent to which of the following
A) if (gender == 1 || age >= 65) {
B) if (gender == 1 && age >= 65)
C) if (gender == 1 AND age >= 65)
D) if (gender == 1 OR age >= 65)
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
60
Which of the following statements is true
A) strings can be used in switch expressions, but string literals cannot be used in case labels.
B) strings cannot be used in switch expressions, but string literals can be used in case labels.
C) strings can be used in switch expressions, and string literals can be used in case labels.
D) strings cannot be used in switch expressions, and string literals cannot be used in case labels.
A) strings can be used in switch expressions, but string literals cannot be used in case labels.
B) strings cannot be used in switch expressions, but string literals can be used in case labels.
C) strings can be used in switch expressions, and string literals can be used in case labels.
D) strings cannot be used in switch expressions, and string literals cannot be used in case labels.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
61
In structured programming,the only two ways to combine control statements are stacking and nesting.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
62
The rule says that any rectangle (action)in an activity diagram can be replaced by two rectangles with round edges.
A) nesting
B) selection
C) stacking
D) None of the above.
A) nesting
B) selection
C) stacking
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
63
The while statement is sufficient to perform any type of repetition.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
64
The stacking and nesting rules must be applied in a specific order.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
65
Which statement below is false
A)Structured programming produces programs that are easier to test.
B)Structured programming requires four forms of control.
C)Structured programming produces programs that are easier to modify
D)Structured programming promotes simplicity.
A)Structured programming produces programs that are easier to test.
B)Structured programming requires four forms of control.
C)Structured programming produces programs that are easier to modify
D)Structured programming promotes simplicity.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
66
Control-statement stacking is the process of:
A) placing control statements within each other
B) placing control statements one after another
C) reducing the number of statements required by combining statements
D) None of the above.
A) placing control statements within each other
B) placing control statements one after another
C) reducing the number of statements required by combining statements
D) None of the above.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck