answersLogoWhite

0

A statement and a function are two separate things. An if statement is a selection statement and has the following forms in C:

if (expression) {

statement;

}

if (expression) {

statement;

} else {

statement;

}

In the first form, the statement executes only when the expression evaluates true. In the second form, the first statement executes when the expression evaluates true, otherwise the second statement executes. The second statement may be another if statement (a nested if):

if (expression) { statement;

} else if (expression) {

statement;

} else {

statement;

}

Here, the second expression is only evaluated when the first expression evaluates false. If both expressions evaluate false, the final statement executes. Note that the final else clause is optional within nested if statements.

Nested ifs can often be thinly-disguised switch statements:

if (x==0) {

f(x);

} else if (x==1) {

g(x);

} else if (x==2) {

h(x);

} else {

i(x);

}

If statements of this type are best implemented using a switch statement:

switch (x) {

case 0: f(x); break;

case 1: g(x); break;

case 2: h(x); break;

default: i(x);

}

As well as being easier to read (and maintain), execution is more efficient as the control expression (x) need only be evaluated once and execution will immediately pass to the appropriate case label (much like a goto statement). With a nested if statement, each expression has to be evaluated in turn until one of them evaluates true, or execution passes to the else clause.

Switch statements are also more flexible in that the default clause need not be the final clause and execution automatically "falls through" to the next case label until a break or return statement is encountered.

User Avatar

Wiki User

7y ago

What else can I help you with?

Continue Learning about Engineering

In C programming language what are the so called functions statement statement block function block and expressions?

Statements are composed from expressions. A semi-colon turns an expression into a statement. A function is not a statement it is a type definition. A statement block is a compound statement, one or more statements delimited by braces, {}. A function block is the body of a function. The body must be enclosed in braces, {}.


What statement can be used to transfer control back to the main program after the execution of a subroutine?

It depends what language you are using. Structured languages provide the easiest method, simply call the function containing your subroutine and control will automatically return to the point of the call when the function ends. You can even use functions to return a value to the caller. If functions are not an option, the language might provide a gosub statement. This is similar to a goto statement but returns control to the caller, much like a function would in a structured language.


What punctuation ends most lines of C and C plus plus code?

C programs are composed from data types and functions. Functions are composed from one or more statements. A statement is composed from one or more expressions terminated by a semi-colon. A semi-colon without an expression is itself a statement (an empty statement). Every C program must have at least one function, the global main function. This serves as the entry-point of the application. When we return from the main function, the program terminates normally. The C standard requires that the global main function return an integer to the execution environment, where the value 0 is conventionally used to indicate "no error". As such, the minimum C program is as follows: int main (void) { return 0; }


What is statement of scale?

A statement scale is a scale that makes a statement!! :) ;) :(


Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).

Related Questions

How many functions does the end statement have?

three functions.......


If government regulated by a written or unwritten statement of principles and functions is called what?

Constitutional Government


Which statement describes how a plant cells functions would change in the absence of a vacuole?

jhgjfh


What function in MS Excel which checks the logical condition of a statement?

IF function


What is true about state functions?

A true statement about state functions is that is a property of a system that only depends on current state of the system. It does not depend on the way the system acquired the state it is in.


In C programming language what are the so called functions statement statement block function block and expressions?

Statements are composed from expressions. A semi-colon turns an expression into a statement. A function is not a statement it is a type definition. A statement block is a compound statement, one or more statements delimited by braces, {}. A function block is the body of a function. The body must be enclosed in braces, {}.


If f x and g x are inverse functions which statement must be true?

f and g are both bijective mappings.


What is statement is not true of the functions of water in the body?

A statement that is not true regarding the functions of water in the body is that water serves as a significant energy source. While water is essential for many bodily functions, such as temperature regulation, nutrient transport, and waste elimination, it does not provide energy like carbohydrates, fats, or proteins do. Instead, water facilitates biochemical reactions and supports cellular processes, but it does not contribute calories or energy.


Cell process affect the entire biosphere Is this statement False?

yes cell processes affect all of bodily functions is false


What statement causes a function to executed in PHP?

All usable statements in PHP can cause a function to be executed - however, that's not to say that every statement will execute a function. A statement is defined by the programmer, who it is ultimately the one responsible for including a function, more than one function, or no functions.


What statement about the pancreas is not true?

A false statement about the pancreas is that it produces only insulin. In reality, the pancreas has both endocrine functions, producing hormones like insulin and glucagon, and exocrine functions, secreting digestive enzymes that aid in the breakdown of food in the small intestine. This dual role is essential for regulating blood sugar levels and facilitating digestion.


Is according to a preposition?

"According to" functions as a preposition in English grammar. It is used to indicate the source of information or the basis for a statement.