Chapter 2 Flashcards
- You want to declare an integer variable called myVar and assign it the value 0. How can you accomplish this?
a. declare myVar as 0;
b. myVar = 0;
c. int myVar = 0
d. int myVar = 0;
b. myVar = 0;
2 You need to make a logical comparison where two values must return true in order for your code to execute the correct statement. Which logical operator enables you to achieve this?
a. AND
b. |
c. &
d. &&
d. &&
- What kind of result is returned in the condition portion of an if statement?
a. Boolean
b. Integer
c. Double
d. String
a. Boolean
- What are the keywords supported in an if statement?
a. if, else, else-if, return
b. if, else, else if
c. if, else, else if, break
d. if, else, default
b. if, else, else if
- In the following code sample, will the second if structure be evaluated?
bool condition = true;if(condition) if(5
a. Yes
- If you want to iterate over the values in an array of integers called arrNumbers to perform an action on them, which loop statement enables you to do this?
a. foreach (int number in arrNumbers)
{
}
b. for each (int number in arrNumbers)
{
}
c. for (int i; each i in arrNumbers; i++)
{
}
d. foreach (number in arrNumbers)
{
}
a. foreach (int number in arrNumbers)
{
}
- What is the purpose of break; in a switch statement?
a. It causes the program to exit.
b. It causes the code to exit the switch statement.
c. It causes the program to pause.
d. It causes the code to stop executing until the user presses a key on the keyboard.
b. It causes the code to exit the switch statement.
- What are the four basic repetition structures in C#?
a. for, foreach, loop, while
b. loop, while, do-for, for-each
c. for, foreach, while, do-while
d. do-each, while, for, do
c. for, foreach, while, do-while
9. How many times will this loop execute? int value = 0; do { Console.WriteLine (value); } while value > 10; a. 10 times b. 1 time c. 0 times d. 9 times
b. 1 time
E1. Which of the following is NOT a comparison operator? a. != b = c. > d. <
b =
E2. Which of the following is the correct syntax for executing the following statements in an if statement?
Console.WriteLine(“In an if statement”);
Console.WriteLine();
a.
bool condition = true;
if(condition)
Console.WriteLine(“In an if statement”);
Console.WriteLine();
Console.WriteLine(“Outside the if statement”);
b.
bool condition = true;
if(condition)
{
Console.WriteLine(“In an if statement”);
Console.WriteLine();
}
Console.WriteLine(“Outside the if statement”);
c.
bool condition = true;
if(condition)
{
Console.WriteLine(“In an if statement”);
Console.WriteLine();
Console.WriteLine(“Outside the if statement”);
}
d.
bool condition = true;
if(condition)
{
Console.WriteLine(“In an if statement”);
}
Console.WriteLine();
Console.WriteLine(“Outside the if statement”);
b. bool condition = true; if(condition) { Console.WriteLine("In an if statement"); Console.WriteLine(); } Console.WriteLine("Outside the if statement");
E3. Which of the following looping structures must end with a semicolon?
a. for
b. foreach
c. do-while
d. while
c. do-while
E4. How do you handle multiple switch statements with one condition in a switch structure?
a. Remove the colon after the condition.
b. Enclose all the code statements you want executed together in curly braces.
c. Create separate switch statements.
d. Omit the break; statement.
structure?
d. Omit the break; statement.
structure?
E5. In a for statement, when does the incrementing of the counter take place?
a. On the last iteration only
b. At the end of each iteration
c. On the second and subsequent iterations only
d. At the end of the iteration and after the comparison
b. At the end of each iteration
E6. When can you assign a value to a variable?
a. During creation only
b. Only runtime in code
c. During declaration
d. Only at design time when writing the code
c. During declaration