Dev C++ Nested If

  • Nested if-else statement. When we validate conditions within the condition, it is called Nested condition checks; here we are using Nested if-else statement. Let suppose, if you have two conditions: CON1 and CON2 and you want to validate CON2, when CON1 is true, in such case we must have to use Nested if.
  • I have a question about Pre-processor directives in c: For example: #ifndef QUESTION //some code here #ifndef QUESTION //some code here #endif #endif Can we use it in this way, and can the C compiler match the ifndef and endif in the right way?
  1. C++ Nested Class Tutorial
  2. Dev C Nested If Formula
  3. Nested If Statement In C
  4. Dev C Nested If Statement
  • C++ Basics
  • C++ Object Oriented

In C we can use if statement in the another else block. Or we can also include if block in the another if block. Syntax: C Nested If if (booleanexpression 1) // Executes when the boolean expression 1 is true if (booleanexpression 2) // Executes when the boolean expression 2.

  • C++ Advanced
  • C++ Useful Resources
  • Selected Reading

An if statement can be followed by an optional else statement, which executes when the boolean expression is false.

Syntax

The syntax of an if..else statement in C++ is −

If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed.

Flow Diagram

Example

When the above code is compiled and executed, it produces the following result −

C++ Nested Class Tutorial

if..else if..else Statement

An if statement can be followed by an optional else if..else statement, which is very usefull to test various conditions using single if..else if statement.

Dev C Nested If Formula

When using if , else if , else statements there are few points to keep in mind.

  • An if can have zero or one else's and it must come after any else if's.

  • An if can have zero to many else if's and they must come before the else.

  • Once an else if succeeds, none of he remaining else if's or else's will be tested.

Syntax

The syntax of an if..else if..else statement in C++ is −

Example

When the above code is compiled and executed, it produces the following result −

Dev c nested if java

Writing a loop inside another loop is known as nested loop. Maximum level of nesting allowed in C++ is 256. We can write while , do..while , for and range based for loop in a nested loop.

Nested While Loop

The syntax of nested while loop is shown below

Below is an example of nested while loop

Below is the output of above program

i = 0 and j = 0
i = 0 and j = 1
i = 0 and j = 2
i = 0 and j = 3
i = 0 and j = 4
i = 1 and j = 0
i = 1 and j = 1
i = 1 and j = 2
i = 1 and j = 3
i = 1 and j = 4
i = 2 and j = 0
i = 2 and j = 1
i = 2 and j = 2
i = 2 and j = 3
i = 2 and j = 4

Nested Do-While Loop

The syntax of nested do…while loop is shown below

Below is an example of nested do…while loop

Below is the output of above program

i = 0 and j = 0
i = 0 and j = 1
i = 0 and j = 2
i = 0 and j = 3
i = 0 and j = 4
i = 1 and j = 0
i = 1 and j = 1
i = 1 and j = 2
i = 1 and j = 3
i = 1 and j = 4
i = 2 and j = 0
i = 2 and j = 1
i = 2 and j = 2
i = 2 and j = 3
i = 2 and j = 4

Nested For Loop

Nested If Statement In C

The syntax of nested for loop is shown below

Below is an example of nested for loop

Below is the output of above program

Trap synth vst free download. i = 0 and j = 0
i = 0 and j = 1
i = 0 and j = 2
i = 0 and j = 3
i = 0 and j = 4
i = 1 and j = 0
i = 1 and j = 1
i = 1 and j = 2
i = 1 and j = 3
i = 1 and j = 4
i = 2 and j = 0
i = 2 and j = 1
i = 2 and j = 2
i = 2 and j = 3
i = 2 and j = 4

Nested Range-Based For Loop

The syntax of nested range-based for loop is shown below

Below is an example of nested for loop

Below is the output of above program

Dev C Nested If Statement

i = 0 and j = 0
i = 0 and j = 1
i = 0 and j = 2
i = 0 and j = 3
i = 0 and j = 4
i = 1 and j = 0
i = 1 and j = 1
i = 1 and j = 2
i = 1 and j = 3
i = 1 and j = 4
i = 2 and j = 0
i = 2 and j = 1
i = 2 and j = 2
i = 2 and j = 3
i = 2 and j = 4