0% found this document useful (0 votes)
62 views3 pages

Decision Making Satement

Conditional statements in C++ allow for conditional execution of code based on logical tests. There are four main conditional statements: 1. If statements execute code if a condition is true or allow else blocks to execute if false. 2. If-else statements provide two-way branching to execute one of two code blocks. 3. Nested if-else statements allow checking multiple conditions with more than two possible outcomes. 4. Switch statements provide multi-way branching to select between multiple alternative code blocks based on a variable's value.

Uploaded by

gmalik16
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views3 pages

Decision Making Satement

Conditional statements in C++ allow for conditional execution of code based on logical tests. There are four main conditional statements: 1. If statements execute code if a condition is true or allow else blocks to execute if false. 2. If-else statements provide two-way branching to execute one of two code blocks. 3. Nested if-else statements allow checking multiple conditions with more than two possible outcomes. 4. Switch statements provide multi-way branching to select between multiple alternative code blocks based on a variable's value.

Uploaded by

gmalik16
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Conditional Control Statements of C++ Language

CONDITIONAL CONTROL STATEMENTS:


Conditional Control Statements involves performing a Logic Test. This Test results either a TRUE or FALSE.

Depending upon the truthness or falsity of the condition, the statememts to be executed is determined. After that, the control transfers to the statement in the program and start executing the statements. This is known as Conditional Execution. In C four conditional control statements are widely used: 1. 2. 3. 4. If-statement If-else statement Nested-if-else statement Switch statement

Let us take all control statements one by one:

If-Statement: This is used to execute a statement or a collection of statements conditionally or you can say that it is used to execute only one action. It is called one way branching. Here the logical condition is tested which results either TRUE or FALSE. Syntax of if statement is if(condition) { statement1; } Where Condition => is a logical expression that results in TRUE or FALSE.

Statement => a simple statement(single statement) or compound statement(collection of two or more statement). Elxpanation: If the logical condition is TRUE then statement1 is executed and If the logical condition is FALSE then control transfers to the next executable statement. If-Else Statement: This is used to execute two statements alternatively. It is called a two way branching.The syntax of if-else statement is

if(condition) { statement1; } else { statement2; } Explanation: If the logical condition is TRUE then statement1 is executed and If the logical condition is FALSE then control transfers to the next executable statement that is statement2. Nested If-Else Statement: It is used if there are more than two alternatives to select.The syntax of nested-if statement is

if(condition1) { if(condition2) { statement1; } else { statement2; } } else { statement3; } Explanation: Statement1 is executed if condition1 and condition2 are TRUE. if condition1 is TRUE and condition2 is FALSE then statement2 is executed. if condition1 is FALSE then control transfer to the else part and statement3 is executed.

Switch Statement: It provides a multiway branching. It allows user to select any one of the several alternatives, depending upon the value of an expression. The value of expression enclosed with in the parentheses. Depending upon the value of expression,the control is transferred to a particular case and statements executed according to the case value.The syntax of switch statement is

switch(expression) { case value1; statement1; break; case value2; statement2; break; case value3; statement3; break; case default; statement n; break; }

You might also like