answersLogoWhite

0


Best Answer

The if-then-else inline command is shown below:

returnvalue = (condition) ? (truePart) : (falsePart);

-----------

According to the C standard, this command does exist in the C coding language in the same way as it exists in C++ and comparable languages.

http://users.ece.cmu.edu/~eno/coding/CCodingStandard.html

User Avatar

Wiki User

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

Wiki User

11y ago

Only one type:

if (<condition>) <statement1>

[else <statement2>]

of course statements can be single statements, blocks, empty statements, etc.

Example:

if (i==1);

else for (j=1; j<=i; ++j) printf ("i==%d j==%d\n", i, j);

I'd say there's 4 kinds of if statements:

if

if-then-else-if

nested if

switch can be considered an if statement too.

C has two types of conditional statements: if and switch.

The "if" statement computes an expression and, if the expression is nonzero, executes a block of code. It can optionally be followed by an "else" statement that executes a block of code if the "if" statement is false. The block of code can have another "if" statement, up to as many "if"s as desired.

The "switch" statement works differently, comparing one value with multiple values.

See the related links below for more information on conditional statements in C.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Firstly, if else is not a structure, "multiway" (whatever that means) or otherwise. It is a control statement.

Secondly, there are only two forms of control statement using if: either with or without the else clause.

The syntax is as follows:

if (expression)

{

statement; // control passes here when expression evaluates true

}

[else

{

statement; // control passes here when expression evaluates false

}]

All expressions must evaluate true or false, or to any boolean equivalent (where zero is false and non-zero is true).

Each statement can either be a simple or a compound statement. All compound statements must be surrounded by braces {}, as shown above, but are optional for simple statements.

Either statement can also be another if statement (nested if). The following example uses assertions to prove the logic:

if (exp1)

{

if (exp2)

{

assert (exp1 && exp2);

}

else

{

assert (exp1 && !exp2);

}

}

else

{

if (exp3)

{

assert (!exp1 && exp3);

}

else

{

assert (!exp1 && !exp3);

}

}

Note that since all if statements are themselves just simple statements, curly braces are optional unless there is any ambiguity regarding which else belongs to which if, otherwise curly braces are only required around compound statements. The above example can therefore be simplified as follows:

if (exp1)

if (exp2)

assert (exp1 && exp2);

else

assert (exp1 && !exp2);

else

if (exp3)

assert (!exp1 && exp3);

else

assert (!exp1 && !exp3);

Note that an else immediately followed by an if is typically placed on the same line to become an else if, however the else and the if are still separate statements:

if (exp1)

if (exp2)

assert (exp1 && exp2);

else

assert (exp1 && !exp2);

else if (exp3) // else if statement

assert (!exp1 && exp3);

else

assert (!exp1 && !exp3);

The following is the same example using compound statements (curly braces are required):

if (exp1)

if (exp2)

{

assert (exp1);

assert (exp2);

}

else

{

assert (exp1);

assert (!exp2);

}

else if (exp3)

assert (!exp1 && exp3);

else

assert (!exp1 && !exp3);

Where you place curly braces around compounds is a matter of personal preference. The following is a fairly common form:

if (exp1)

if (exp2) {

assert (exp1);

assert (exp2);

} else {

assert (exp1);

assert (!exp2);

}

else if (exp3)

assert (!exp1 && exp3);

else

assert (!exp1 && !exp3);

When the logic is not clear, use braces and/or indentation as appropriate.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The 'if' statement in C++ allows the programmer to specify that a section of code should be run if the condition to the 'if' statement is true, skipped otherwise.

if(condition)

{

std::cout << "This prints if the value of "condition" is true." << std::endl;

}

std::cout << "This prints independent of the truth value of "condition"." << std::endl;

(Pretend there are backslashes before the inner quotes in above print statements. Answers.com has stripped them out.)

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

There is no else-if-then statement in any language. C++ uses the if/else if/else statement, where the first if is mandatory (introducing the statement) but the remaining clauses are optional. If present, the else clause must be the final clause, with one or more else if's in between, if required.

Example:

if( x )

{

// ... statements to execute when x is non-zero

}

else

{

// ... statements to execute when x is zero

}

if( x==1 )

{

// ... statements to execute when x is 1

}

else if( y==1 )

{

// ... statements to execute when x is not 1 but y is 1

}

else

{

// ... statements to execute when neither x nor y are 1

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

There is no "endif" keyword in C++.

if(expression)

statement

[else

statement]

Either statement may be another if expression (nested if):

if(expression)

statement

else if(expression)

statement

else

statement

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Please re-word your question.

The if/else construct allows your program to make decisions. Here is an example:

if (number1 < number2)

{

//do some stuff here...

}

else

{

//do some more stuff here...

}

When the program comes upon an if statement, it evaluates the expression to see if it is true. If it is, it executes the instructions inside the if statement. If the expression is found to be false, it executes the optional else statement.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The difference between if-else and conditional operator is that IF-ELSE statement is easy to understand.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the if-else statement in c plus plus programming language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

When was Plus - programming language - created?

Plus - programming language - was created in 1976.


Is the ccc plus language for programming?

CCC+ is a sovereign credit rating. It is not a programming language.


What is the use of c plus plus in banks?

Programming language.


Who is the owner of c plus plus language?

Bjarne Stroustrup is the author of C++. However, no one "owns" this language.


Who is founder of C plus plus programming language?

Bjorn Stroustrup


Is c plus plus an unstructured programming language?

No, BASIC is, for example.


Is score a reserved word in the C plus plus programming language?

No.


Who designed the C plus plus programming language?

Bjarne Stroustrup


Which type of language c plus plus is?

It's an imperative, procedural and Object-Oriented programming language.


What is the significance of c plus plus?

C++ is an object oriented programming language


What is structured programming language in C plus plus?

Your question makes no sense.


Who designed and implemented the c plus plus programming language?

Bjarne Stroustroup