answersLogoWhite

0


Best Answer

I would recommend an If - then - else statement over a switch statement because:

1. It is simpler/easier

2. You do not get unexpected output because of missing break statements

A missed break statement in one of the conditions in a switch case statement means that all the conditions that come after the success condition are executed. In case of if else this is not the case and hence it is much safer for novice programmers.

> essentially perform the same function

No, they don't. Here is an example to prove this:

if (sin (alpha) > cos (alpha)) {

...

} else if (alpha / M_PI * 180 > 180) {

...

} else {

...

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If then else statements and case statements essentially perform the same function when would you use one over the other?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is function in oop?

A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed from as many different points in a C Program as required.Function groups a number of program statements into a unit and gives it a name. This unit can be invoked from other parts of a program. A computer program cannot handle all the tasks by it self. Instead its requests other program like entities - called functions in C - to get its tasks done. A function is a self contained block of statements that perform a coherent task of same kindThe name of the function is unique in a C Program and is Global. It neams that a function can be accessed from any location with in a C Program. We pass information to the function called arguments specified when the function is called. And the function either returns some value to the point it was called from or returns nothing.We can divide a long C program into small blocks which can perform a certain task. A function is a self contained block of statements that perform a coherent task of same kind.Structure of a FunctionThere are two main parts of the function. The function header and the function body.int sum(int x, int y){int ans = 0; //holds the answer that will be returnedans = x + y; //calculate the sumreturn ans //return the answer}


What statement is like a chain of if then else statements they perform their tests one after the other until one of them is found to be true?

Language-dependent, it can be switch, select, case or something similar.


What is the statements written by the programmer are called?

They are called statements. They have no other special name. A group of statements are called "Block statements".


What is a block in c plus plus?

Assuming you mean a code block, a group of simple statements enclosed in braces {} is regarded as a code block. In other words, a compound statement. Braces are not required around simple statements except when the statement is the body of a function (where braces are mandatory).


Why transformer is only used instead of any other device?

A transformer is the primary device which transforms voltage to a higher or lower voltage. In electronics, capacitors and resistors perform this function.

Related questions

What is a function procedure in Visual Basic?

A function is essentially a subroutine that is ment to be used by other subroutines.


What other function does the ear perform?

cheese balls


Do tissue work with other structures to perform a function?

yes


Do organ system work with other structures to perform a function?

yes


Does the organ system work with other structures to perform a function?

yes it does.


Does a cell work together with other structures to perform a function?

yes


What is function in oop?

A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed from as many different points in a C Program as required.Function groups a number of program statements into a unit and gives it a name. This unit can be invoked from other parts of a program. A computer program cannot handle all the tasks by it self. Instead its requests other program like entities - called functions in C - to get its tasks done. A function is a self contained block of statements that perform a coherent task of same kindThe name of the function is unique in a C Program and is Global. It neams that a function can be accessed from any location with in a C Program. We pass information to the function called arguments specified when the function is called. And the function either returns some value to the point it was called from or returns nothing.We can divide a long C program into small blocks which can perform a certain task. A function is a self contained block of statements that perform a coherent task of same kind.Structure of a FunctionThere are two main parts of the function. The function header and the function body.int sum(int x, int y){int ans = 0; //holds the answer that will be returnedans = x + y; //calculate the sumreturn ans //return the answer}


What the heck is a kapo?

essentially a squad leader, a prisoner who was made responsible for other prisoners. If they did not perform, then he would suffer.


Buds produce new growth and perform what other function?

Gas Exchange


What is a method in Java?

A Java method is a sequence of statements. It is comparable to a function, subroutine, or procedure in other languages.


What are consequences of cell specialization?

The cells may lose the ability to perform other function.


Can a transistor alone perform the function of an amplifier?

No, it needs several other components and a source of power.