Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 1 When you place an if statement within another if statement, ____. you

ID: 3832414 • Letter: Q

Question

QUESTION 1

When you place an if statement within another if statement, ____.

you create a nested if statement

a syntax error is generated

curly braces are required

you create a switch statement

QUESTION 2

What is the rule for lining up, or matching, elses?

Else goes with the closest previous if that does not have its own else.

Else matches the closest if that follows it.

The first else goes with the first if.

The else goes with the one that is indented identically to it.

QUESTION 3

The rule for lining up, or matching, elses is that the else is matched with the first if, from top to bottom.

True

False

QUESTION 4

if (examScore is less than 50)
display message “Do better on next exam”

The result of the expression above is ____.

numeric

true

true or false

100

QUESTION 5

The switch statement case value can evaluate to all of the following EXCEPT ____.

char

int

string

double

QUESTION 6

Which of the following statements is NOT true regarding switch statements?

A variable cannot be used as the case label.

Default is only executed when there is no match.

Default is required.

The expression is sometimes called the selector.

  

QUESTION 7

With an if statement, when you place a semicolon on the line that has the conditional expression, you create a null (empty) statement body for the true portion of the if statement.

True

False

QUESTION 8

When you have a single variable being tested for equality against four or more values, a one-way selection statement is the most appropriate type of conditional expression to use.

True

False

QUESTION 9

In C#, the && and || operators are also called the short-circuiting logical operators.

True

False

QUESTION 10

if (examScore > 89)
     grade = ‘A’;
     Console.WriteLine(“Excellent”);

Using the code snippet above, when does Excellent get displayed?

never, a syntax error is generated

every time the program is run

whenever the score is greater than 89

when the score is less than or equal to 89

a.

you create a nested if statement

b.

a syntax error is generated

c.

curly braces are required

d.

you create a switch statement

Explanation / Answer

if inside if creates nested if statement. Syntax is as follows: -

if(condition1) {

        if(condition2) {

        }

}

The rule is that else belongs to previous if that does not have its own else. It’s not the first if.

in if block expression must have value either true/false

switch not possible on a value of type double. Only convertible int values, strings,char or enum variables are permitted

Expression is called decision not selector.

If we place semicolon, it implies that statement is ended, so nothing is there for true part.

As Because of their short circuiting behavior, the second condition is not evaluated at run time if the operator result is known after evaluating the first condition.

Because there is no parenthesis after if block, so the first next statement will be the part of if. Rest all will run every time we run the code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote