Javatpoint Logo
Javatpoint Logo

Decision Making

The decision making in a programming language is similar to decision making in real life. In a programming language, the programmer uses decision making for specifying one or more conditions to be evaluated by the program. The decision making always returns the Boolean result true or false.

There are various types of Decision making in TypeScript:

  • if statement
  • if-else statement
  • if-else-if ladder
  • nested if statement

if statement

It is a simple form of decision making. It decides whether the statements will be executed or not, i.e., it checks the condition and returns true if the given condition is satisfied.

Syntax


Decision Making

Example

Output:

a is less than b.

if-else statement

The if statement only returns the result when the condition is true. But if we want to returns something when the condition is false, then we need to use the if-else statement. The if-else statement tests the condition. If the condition is true, it executes if block and if the condition is false, it executes the else block.

Syntax


Decision Making

Example

Output:

The input value is positive Number: 10

if-else-if ladder

Here a user can take decision among multiple options. It starts execution in a top-down approach. When the condition gets true, it executes the associated statement, and the rest of the condition is bypassed. If it does not find any condition true, it returns the final else statement.

Syntax


Decision Making

Example

Output:

A+ grade

Nested if statement

Here, the if statement targets another if statement. The nested if statement means if statement inside the body of another if or else statement.

Syntax


Decision Making

Example

Output:

The largest number is: 25




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA