IDNLearn.com is your go-to resource for finding precise and accurate answers. Get prompt and accurate answers to your questions from our community of knowledgeable experts.

What is wrong with this case statement -> case (x > 2):
A. cases can't have a test condition
B. cases must be capitalized
C. cases must use a ; and not a :


Sagot :

Answer:

A: cases can't have a test condition

Explanation:

Under the hood, switch statements don't exist. During the mid-stage of compilation, a part of the compiler will lower the code into something that is easier to bind. This means that switch statements become a bunch of if statements.

A case in a switch statement acts upon the switch value. Think of the case keyword as the value you pass into the switch header:

int x = 10;

switch (x)

{

case (x > 2):

     // Code

     break;

}

// Becomes

if (x(x > 2))

{

// Code

}

// Instead do:

switch (x)

{

case > 2:

     // Code

     break;

}

// Becomes

if (x > 2)

{

// Code

}