Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Nested if...else Statement

var number = 5
// outer if statement
if (number >= 0) {

  // inner if statement
  if (number == 0) {
      print("Number is 0")
  }

  // inner else statement
  else {
      print("Number is positive");
  }
}

// outer else statement
else {
    print("Number is negative");
}
Comment

nested if statement

if (condition) {

  if (anotherCondition) {
    // executes if both condition and anotherCondition are true
  } else {
    // executes if condition is true and anotherCondition is false
  }

} else {
  // executes if condition is false
}
Comment

Nested if...else Statement

using System;
 
namespace Conditional
{
	class Nested
	{
		public static void Main(string[] args)
		{
			int first = 7, second = -23, third = 13;
			if (first > second)
			{
				if (firstNumber > third)
				{
					Console.WriteLine("{0} is the largest", first);
				}
				else
				{
					Console.WriteLine("{0} is the largest", third);
				}
			}
			else
			{
				if (second > third)
				{
					Console.WriteLine("{0} is the largest", second);
				}
				else
				{
					Console.WriteLine("{0} is the largest", third);
				}
			}
		}
	}
}
Comment

Example of Nested IF Statement

public class Test {

   public static void main(String args[]) {
      int x = 30;
      int y = 10;

      if( x == 30 ) {
         if( y == 10 ) {
            System.out.print("X = 30 and Y = 10");
         }
      }
   }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: read string with spaces in c++ 
Cpp :: enum c++ 
Cpp :: how to find even and odd numbers in c++ 
Cpp :: polymorphism in c++ 
Cpp :: is anagram c++ 
Cpp :: lambda function in c++ 
Cpp :: dice combinations cses solution 
Cpp :: do while c++ 
Cpp :: online ide c++ 
Cpp :: c++ find index of element in array 
Cpp :: sfml keyboard events cpp 
Cpp :: one away coding question 
Cpp :: prevent copy c++ 
Cpp :: glm has no member value_ptr 
Cpp :: c++ variable type 
Cpp :: copy constructor c++ syntax 
Cpp :: vector::at() || Finding element with given position using vector in C++ 
Cpp :: c++ pass ofstream as argument 
Cpp :: lists occurrences of characters in the string c++ 
Cpp :: C++ detaching threads 
Cpp :: DS1302 
Cpp :: executing an opencv c++ code 
Cpp :: minimum characters to make string palindrome 
Cpp :: copy constructor for vector c++ 
Cpp :: C++ pointer to base class 
Cpp :: min heap 
Cpp :: c++ virtual function 
Cpp :: online converter c++ to c 
Cpp :: vector insert to end 
Cpp :: How do you count the occurrence of a given character in a string? c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =