answersLogoWhite

0

What are IF statement functions?

Updated: 8/10/2023
User Avatar

Wiki User

6y ago

Best Answer

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

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

As far as I know, there is no such thing as a "statement function". An "if" statement is a construct, in a programming language, that lets you execute a certain instruction (or more than one) only if a condition you specify is fulfilled. For example:
IF age < 18

{

print "This activity is not allowed for underage children."

}


In this example, if the person is NOT underage, there is no need to show the message.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Statements are not functions per dephinitionem, but a function-calling can be a statement.

So the answer is not.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

No. Statements and functions are different things. For example if, for, while, return are statements, sin, strlen, printf are functions.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Yes, example: if (strcmp (a, b)=0) puts ("Equals");

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are IF statement functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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 a return statement used for?

It means end the function. Functions automatically end when execution reaches the end of the function, but you can return from a function at any point within the function with a return statement. If the function returns a value to its caller, you must provide a reachable return statement along with the value you wish to return.


What is statement of scale?

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

Related questions

How many functions does the end statement have?

three functions.......


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

jhgjfh


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

Constitutional Government


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.


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

IF function


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.


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.


Which statement correctly describes one characteristics of the tubelike digestive system of a earthworm?

Various parts of the system perform different digestive functions.


Which is the most valid statement concerning the social welfare programs of the new deal?

Government assumed responsibility for functions previously performed by other institutions.


Issue specific security policy?

(ISSP) A statement of the organization's position which functions to instruct employees on proper use of technologies and processes as they pertain to a specific issue.