answersLogoWhite

0

Structure of If-Then statement

Updated: 8/10/2023
User Avatar

Wiki User

12y ago

Best Answer

if (condition) statement1

[else statement2]

example:

if (i==j);

else if (j==k) printf ("i!=j, j==k\n);

else printf ("i!=j, j!=k\n);

here statement1 is an empty-statement, statement2 is another if-statement

There are three forms of statements

IF-THEN

IF-THEN-ELSE

IF-THEN-ELSIF

Sequence of statements is executed only if the condition evaluates to TRUE

If condition evaluates to FALSE or NULL, it does nothing

In either case control passes to next statement after the IF-THEN structure

IF THEN

statements;

END IF;

Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL

IF THEN

statements;

ELSE

statements;

END IF;

User Avatar

Wiki User

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

Wiki User

8y ago

It depends on the language however most use the following syntax:

if (expression) then statement else statement endif

Note that the "then" and "endif" keywords are not used in all languages since they are implied by the statement's structure and are normally only found in verbose languages such as BASIC. In C and C++, for instance, we have the following form:

if (expression) {

statement;

} else {

statement;

}

The expression must be a boolean expression; one that evaluates true or false. If the expression evaluates to a number, the expression evaluates true when the number is non-zero, otherwise it is false. When the expression is true, the first statement is executed otherwise the second statement is executed.

Often we do not wish to execute anything when an expression is false, only when it is true, so the else clause is optional.

if (expression) statement;

In languages that use braces {} to denote structure, they are usually optional for simple statements but mandatory for compound statements. A compound statement is a group of statements that are treated as being one statement.

Either statement may itself be an if statement (a nested if):

if (expression) {

if (expression) {

statement;

} else {

statement;

}

} else {

statement;

}

Spreading if statements over multiple lines and using whitespace indentation helps to highlight the logic and structure of the statement. It is not possible to show whitespace indentation here, but here's the same example using periods instead of whitespace:

if (expression) {

...if (expression) {

......statement;

...} else {

......statement;

...}

} else {

...statement;

}

Note the use of blank lines to separate the inner (nested) if from the outer if.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

They are selection statements. If the condition with if is true then the statement attached with if part is executed, otherwise else part is executed.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

"If" first tests a condition. If true, the program executes. If false, each "then else" is tested in order of existence (if there are "else" conditions).

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

A decision statement.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

Binary logic.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

hypothesis

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Structure of If-Then statement
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Structure of cash flow statement?

structure of cash flow statement as follows:1


What is the deductive structure?

A statement or a conclusion that has been deduced.


What is a statement that is ambiguous to its grammar or structure?

syntaxtically incorrect


Basic control structure available in c plus plus?

The basic control structure in C++ is the if statement.


Which statement about the annexation Hawaii are true?

A, it changed the social structure of hawaii


How can you summarize what you want to say in a concise thesis statement?

ANSWER: Structure


A statement is ambiguous due to its grammar or structure?

Syntactic ambiguity


The statement below refers to a structure of the cell oxygen diffuse through this structure but sodium ion may need active transport which structure is this statement most likely referring to?

a semipermeable membrane


What is the definition of 'nested' in C programming?

In C a structure within a structure is called nested. For example, you can embed a while loop in another while loop or for loop in a for loop or an if statement in another if statement.


Which statement in C plus plus is used to implement a decision structure in its simplest form-that of choosing between two alternatives?

if (condition) statement else statement;


What structure allows you to test the value of a variable or an expression and then use that to determine which statement or set of statements to execute?

multiple alternative decision structure / case structure


What is is a true statement about the way writers use sentence structure in literary works?

Sentence structure varies depending on the writers purpose.