Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to show if...else statement using a flowchart in JavaScript?
The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Let's see how to show if...else statement using flowchart in JavaScript.
If...Else Statement Flowchart
Syntax
if (condition) {
// Code to execute if condition is true
} else {
// Code to execute if condition is false
}
Basic Example
let age = 18;
if (age >= 18) {
console.log("You are eligible to vote");
} else {
console.log("You are not eligible to vote");
}
You are eligible to vote
Multiple Conditions with else if
let score = 85;
if (score >= 90) {
console.log("Grade: A");
} else if (score >= 80) {
console.log("Grade: B");
} else if (score >= 70) {
console.log("Grade: C");
} else {
console.log("Grade: F");
}
Grade: B
Flowchart Explanation
The flowchart shows the logical flow of an if...else statement:
- Start: Program execution begins
- Condition: The boolean expression is evaluated
- True path: If condition is true, execute the if block
- False path: If condition is false, execute the else block
- Merge: Both paths merge to continue with the next statement
- End: Program execution continues
Practical Example with User Input
let temperature = 25;
if (temperature > 30) {
console.log("It's hot outside");
} else {
console.log("It's not too hot");
}
console.log("Weather check complete");
It's not too hot Weather check complete
Conclusion
The if...else statement follows a clear decision-making flow as shown in the flowchart. It evaluates a condition and executes one of two code blocks, then continues with the rest of the program.
Advertisements
