What Is If Statement and Use In JavaScript, PHP, Python, Java, C/C++, C#, PowerShell, Bash Programming Languages – POFTUT

What Is If Statement and Use In JavaScript, PHP, Python, Java, C/C++, C#, PowerShell, Bash Programming Languages

All programming languages provide conditional statements in order to change the flow of the programs according to given conditions. If statement is most popular conditional statement provided very similar most of the programming languages. If statements provide single or most flow path according to given conditions like count, size, text, etc.

General If Statement Syntax

As stated previously If statement for different programming languages has very similar syntax. Below is the generic syntax which is used in If statement.

  • if is used for the start of the statement
  • CONDITION is the condition of it should be met
  • elseif is used to provide an extra branch according to new condition. There may be extra elseif with new conditions
  • else is used to but the last branch if previously defined branches or conditions do not meet.

Java If Statement

We can use if statements in Java like below.

Single If Statement

We will use the time conditions where if it is lower than 18 we will print Good Day to the screen.

Multiple If Statements

We will use the time conditions where if it is lower than 18 we will print Good Day to the screen if not we will print Good evening to the screen.

LEARN MORE  Awk If, If Else , Else Statement or Conditional Statements

PHP If Statement

We can implement PHP if statement like below.

Single If Statement

We will use single if statement which will print salute according to the time of the day.

Multiple If Statements

We can also use multiple if statements like below.

Python If Statement

Single If Statement

We can use a single if statement in Python like below.

Multiple If Statements

We can also use multiple if statements like below.

JavaScript If Statement

We can implement Python if statement like below.

Single If Statement

We can use a single if statement in JavaScript like below.

Multiple If Statements

We can also use multiple if statements in JavaScript like below.

LEARN MORE  Linux Bash IF - ELIF - ELSE Conditionals Tutorial with Examples

C/C++ If Statement

C and C++ programming languages provide if statement like below.

Single If Statement

Single if statement will be like below.

Multiple If Statements

Multiple if statements will be like below.

C# If Statement

C# provides very similar syntax to the Java for the If statement.

Single If Statement

We will use the time conditions where if it is lower than 18 we will print Good Day to the screen.

Multiple If Statements

We can use multiple if statements for C# like below.

PowerShell If Statement

Single If Statement

Single if statement for the PowerShell will be like below.

Multiple If Statements

Multiple if statement for the PowerShell will be like below.

LEARN MORE  Powershell If-Elseif-Else Conditional Statement

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)