Decision Making statements
Decision statements are used to control the flow of a program based on conditions.
If…else: The if…else Statement enables the execution of different blocks of code depending on a condition.
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
if condition:
# code to execute if condition is true
else:
# code to execute if condition is false
if…else if… : The if…else if…else statement allows checking multiple conditions one, after another.
if (condition1) {
// code to execute if condition1 is true
} else if (condition2) {
// code to execute if condition2 is true
} else {
// code to execute if all conditions are false
}
if (condition1) {
// code to execute if condition1 is true
} else if (condition2) {
// code to execute if condition2 is true
} else {
// code to execute if all conditions are false
}
if (condition1) {
// code to execute if condition1 is true
} else if (condition2) {
// code to execute if condition2 is true
} else {
// code to execute if all conditions are false
}
if condition1:
# code to execute if condition1 is true
elif condition2:
# code to execute if condition2 is true
else:
# code to execute if all conditions are false
let condition1 = true;
let condition2 = false;
if (condition1) {
console.log("Condition 1 is true.");
} else if (condition2) {
console.log("Condition 2 is true.");
} else {
console.log("All conditions are false.");
}
Switch Statements: The switch statement is utilized to create branches based on the value of an expression.
switch (expression) {
case value1:
// code block
break;
case value2:
// code block
break;
default:
// code block
}
switch (expression) {
case value1:
// code block
break;
case value2:
// code block
break;
default:
// code block
}
switch (expression) {
case value1:
// code block
break;
case value2:
// code block
break;
default:
// code block
}
def switch(someCase):
if case1:
// code block
elif case2:
// code block
elif case3:
// code block
else:
// code block
switch (expression) {
case value1:
// This block of code is executed if the expression equals value1
break;
case value2:
// This block of code is executed if the expression equals value2
break;
default:
// This block of code is executed if the expression doesn't match any of the cases
}
How to Start Coding
In this ever-evolving digital landscape, the ability to code is not just a valuable asset but a gateway to creative expression and innovation. This brief guide will outline practical steps and essential principles to guide aspiring learners on their path to mastering the art of coding.
Table of Content
- Introduction, to Basic Syntax. Hello World
- Understanding Data Types
- Variables and Constants
- Keywords
- Operators
- Decision Making statements
- Loops
- Numbers
- Characters
- Arrays
- Strings- Basic String Concepts
- Functions
Contact Us