Control Flow Statements in Java

Control Flow Statements in Java

By - Kuldeep Singh4/22/2025

Java control flow statements regulate the order and method by which codes execute, managing the program's action depending on conditions and loops. Do not forget to check out our post on Learn Java Programming

Try this not all code so mean There is loging code on when login and when logout there will be log out code run time our login and loout.

if(){

 

}

if(true){

 

}

//here the condition should be true then only it will execute the code which is written in curly braces and vice versa

const isUserloggedIn = true

if (isUserloggedIn){

 

}

// here where the app will crash when this condition executes

To check the condition we have operators (less than , less than equal to =, equals = = and not equals!). = = = strict equality operator === it is use for type checking.

= Single equal is for asignment operator

if (2 == ‘2’){

console.log(“execute”);

}

//here if condition will run

if (2 == ‘2’){

console.log(“execute”);

}

console.log(“Nor execute”);

//here both will print

if (2!= 3){

console.log(“execute”);

}

console.log(“Nor execute”);

//here both will print

if (2!== 3){

console.log(“execute”);

}

console.log(“Nor execute”);

//here both will print

const isUserloggedIn = true

const temperature = 41

if ( temperature < 50 ){

console. log(“less than 50”);

}

console. log(“temperature is greater than 50”);

//here both will print

Explore Other Demanding Courses

No courses available for the selected domain.

const isUserloggedIn = true

const temperature = 41

if ( temperature 100) {

let power = “fly”

console. log(User power: ${power});

}

//output is User power: fly

const score = 200

if (score > 100) {

let power = “fly”

console. log(User power: ${power});

}

console. log(User power: ${power});

console.log(“Run”);

//here we will get error that power is not defined becz we are calling the power variable outside the range.

//Short hand property

const balance = 1000

if (balance > 500) console. log(“test”),console. log(“test2”);

//output test test2

 

//nested if else

if (balance > we use switch case=>

switch case is when we have lots of looks and one key if the that key comes with matching look then we can open the lock.

 

const month = “march”

 

switch (month) {

case 1:

console. log(“January”);

break;

case 2:

console.log(“feb”);

break;

case 3:

console.log(“march”);

break;

case 4:

console.log(“april”);

break;

 

default:

console. log(“default case match”);

break;

}

Output is=> march

 

The significance of break is if we exclude the break from last of every line and assume any one condition satisfies then case will be output and after that match condition cases will print with natural sequence only default case will not output it out means it execute when no case gets matched. Well, this will be taken care by a break statement to overcome this issue. So we can say that, break will ‘Break’ the control flow.

Let's say we have a string =>

//switch case with string value

const month = “march”

switch (month) {

case “jan”:

console. log(“January”);

break;

case “feb”:

console.log(“feb”);

break;

case “march”:

console.log(“march”);

break;

case “april”:

console.log(“april”);

break;

 

default:

console. log(“default case match”);

break;

}

 

Nullish Coalescing Operator (?? ) =>

For the most part, I will refer to null OR undefined.

let val1;

val1 = 5?? 10

console.log(val1); //5

 

For Free, Demo classes Call: 020-71173125 More update visit us : www.royalit.in/

Registration Link: Click Here!

 

As we can see we are being returned the first value so lets do it =>?? => is while we are calling data with the help of database or we are using Firebase that time if we want to take a response so i need to focus now about this related point while we trying means they will not received a direct but at that time only two values and becz of this our function maybe returning null or maybe nothing means undefine when our lot off things effect in whole code structure. So in as such case = > Nullish Coalescing Operator (?? ). The above can be written as the Electron operator acting as a gate or null check.

let val1;

val1 = null?? 10

console.log(val1); //10

 

let val1;

val1 = undefined?? 20

console.log(val1); //20

 

let val1;

val1 = null?? 10?? 20

console.log(val1); //10

 

Terniary Operator=>

condition? true : false

const iceTeaPrice = 100

iceTeaPrice <= 80? console. log(“less than 80”) : console. log(“greater than 80”) //more than 80

Do watch the video on Java: Click Here 

Get Free Consultation

Loading...

Call the Trainer and Book your free demo Class..... Call now!!!

| SevenMentor Pvt Ltd.

© Copyright 2025 | SevenMentor Pvt Ltd.

Share on FacebookShare on TwitterVisit InstagramShare on LinkedIn