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

% Question{01}: Which statement is true about an \"if\" statement? % A. it must

ID: 3860897 • Letter: #

Question

% Question{01}: Which statement is true about an "if" statement?

% A. it must have an expression that evaluates to "true" (i.e. the "true"

% statements MUST run)

% B. it must have an else

% C. it must have an expression that returns a logical (true or false)

% D. it can only evaluate one value at a time

% E. none of the above

Answer{01}='';

Reason{01}='';

% Question{02}: Which statement is true about an "if-elseif-else-end"?

% A. it can not be used to replace multiple "if-else-end"

% B. it can be used to evaluate multiple expressions

% C. it must have an expression that evaluates to "true" (i.e. the "true"

% statements MUST run)

% D. there is a limit to the number of "elseif" expressions

% E. none of the above

Answer{02}='';

Reason{02}='';

% Question{03}: Which statement is true about a "switch" statement?

% A. switch statements can not replace "if-elseif-else-end"

% B. it must have a case expression that evaluates to "true" (i.e. the

% "true" statements MUST run)

% C. only the statements inside the first true case expression will execute

% D. switch expressions are limited to logicals

% E. none of the above

Answer{03}='';

Reason{03}='';

Explanation / Answer

Answer{01}=C

Reason{01}=every if statement or condition must have an expression that returns a logical (true or false). This is main(primary)syntax of if statement.

Example:

int num=10;

if(num>20) or if(num<20)

the syntax is true, in both case we have flase and true logicals. Hence answer is C.

Answer{02}=B(it can be used to evaluate multiple expressions)

Reason{02}=we use if elseif else end statements to evaluate muliple expressons.

Exmple:

int marks=83;

if(marks>90)

return 'A';

else if(marks<60)

return 'B';

else

return 'D';

Answer{03}=B

Reason{03}= Switch statement must have case expression that evaluates to true. When case evaluates to true, the true statements run.

Example:

int i=2;

switch(i)

{

case 1: return 1; break;

case 2: return 2; break;

}