Types of Java Statement
Control Statement
Assignment Statement
Control Statements
Conditional execution
Looping
Flow Control Statement
Types of Conditional Execution
If Statement
If – Else statement
If- Else-if statement
Switch Statement
If Statement
If statement in java encloses some code which is executed only if a condition is true. If statement only takes a boolean expression as its condition.
Note*: Unlike other languages Java does not accept numbers as conditional operators. It only considers boolean expressions as conditions which returns TRUE / FALSE.
Syntax of If Statement
if (true)
System.out.println("Hello! This will always get printed");
If Else Statement
If Else statement consists of one if condition and and one else part. It encloses some code which is executed only if the if condition is true, if its false then the else part of the code will be executed. If else statement takes boolean expression as its condition.
Note*: Unlike other languages, Java does not accept numbers as conditional operators. It only considers boolean expressions as conditions which returns TRUE / FALSE.
E.g if(1==1) is accepted as it is boolean expression and will return true. if(x=1) statement is not allowed in java.
If Else If Statement
If Else If statement consists of multiple if conditions and and an else part. If the if condition is true then the enclosed code will be executed. But if the if condition is false then it will check for the next if condition. If the next if condition is true then the enclosed code will be executed otherwise the else part of the code will be executed. If Else If statements takes boolean expression as its condition .
Note*: Unlike other language Java doesn’t accept numbers as conditional Operator. Only thing that can be accepted as condition is boolean expression which returns TRUE / FALSE.
E.g If(x=1) is not allowed while if(1==1) is accepted as it is boolean expression and will return true.
Types of Looping Statement
For Loop
While Loop
Do - While Loop
Types of Flow Control Statement
Return Statement
Continue Statement
Break Statement
Control Statement
Assignment Statement
Control Statements
Conditional execution
Looping
Flow Control Statement
Types of Conditional Execution
If Statement
If – Else statement
If- Else-if statement
Switch Statement
If Statement
If statement in java encloses some code which is executed only if a condition is true. If statement only takes a boolean expression as its condition.
Note*: Unlike other languages Java does not accept numbers as conditional operators. It only considers boolean expressions as conditions which returns TRUE / FALSE.
Syntax of If Statement
if (true)
System.out.println("Hello! This will always get printed");
If Else Statement
If Else statement consists of one if condition and and one else part. It encloses some code which is executed only if the if condition is true, if its false then the else part of the code will be executed. If else statement takes boolean expression as its condition.
Note*: Unlike other languages, Java does not accept numbers as conditional operators. It only considers boolean expressions as conditions which returns TRUE / FALSE.
E.g if(1==1) is accepted as it is boolean expression and will return true. if(x=1) statement is not allowed in java.
If Else If Statement
If Else If statement consists of multiple if conditions and and an else part. If the if condition is true then the enclosed code will be executed. But if the if condition is false then it will check for the next if condition. If the next if condition is true then the enclosed code will be executed otherwise the else part of the code will be executed. If Else If statements takes boolean expression as its condition .
Note*: Unlike other language Java doesn’t accept numbers as conditional Operator. Only thing that can be accepted as condition is boolean expression which returns TRUE / FALSE.
E.g If(x=1) is not allowed while if(1==1) is accepted as it is boolean expression and will return true.
Types of Looping Statement
For Loop
While Loop
Do - While Loop
Types of Flow Control Statement
Return Statement
Continue Statement
Break Statement