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.

C++
if (condition) {
    // code to execute if condition is true
} else {
    // code to execute if condition is false
}
C
if (condition) {
    // code to execute if condition is true
} else {
    // code to execute if condition is false
}
Java
if (condition) {
    // code to execute if condition is true
} else {
    // code to execute if condition is false
}
Python
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.

C++
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
}
C
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
}
Java
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
}
Python
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
JavaScript
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.

C++
switch (expression) {
    case value1:
        // code block
        break;
    case value2:
        // code block
        break;
    default:
        // code block
}
C
switch (expression) {
    case value1:
        // code block
        break;
    case value2:
        // code block
        break;
    default:
        // code block
}
Java
switch (expression) {
    case value1:
        // code block
        break;
    case value2:
        // code block
        break;
    default:
        // code block
}
Python
def switch(someCase):
    if case1:
        // code block
    elif case2:
        // code block
    elif case3:
        // code block
    else: 
        // code block
JavaScript
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

Similar Reads

1. Introduction, to Basic Syntax. Hello World:

Lets learn the basic syntax of hello world program in different programming languages such as C, C++, Java and Python...

2. Understanding Data Types:

Data types are crucial, in specifying the type of data that can be stored within a variable. Common data types encompass integers, floating point numbers, characters and various others....

3. Variables and Constants:

In programming variables act as containers for data that can be altered during the execution of a program. Conversely constants store data that remains unchanged throughout its course....

4. Keywords:

Keywords are reserved words within a programming language that hold predefined meanings. It’s basically important to note that they cannot be used as names or identifiers....

5. Operators:

Operators are tools for performing operations on variables and values within code....

6. Decision Making statements:

Decision statements are used to control the flow of a program based on conditions....

7. Loops:

Entry Condition Loop:...

8. Numbers:

Performing operations, on numbers involves addition, subtraction, multiplication and division....

9. Characters:

Special characters called escape sequences are used to represent printable characters, such, as newline and tab....

10. Arrays:

Arrays are data structures that are utilized to store and manipulate collections of elements. In languages, like C and C++ arrays are declared with a predetermined size. Initialized with values while in Java, dynamic arrays can be initialized using braces. Python on the hand provides a syntax for creating arrays. Regardless of the programming language used elements, within arrays can be accessed through indices, enabling retrieval and manipulation of data stored in the arrays....

11. Strings- Basic String Concepts

Strings, which are sequences of characters are data types, in programming languages. They serve the purpose of representing and manipulating information. Common tasks performed on strings include combining them extracting substrings determining their length and comparing them....

12. Functions:

Functions are, like building blocks of code that can be reused to accomplish tasks. They play a role in organizing code making it easier to read and maintain. When defining a function you enclose a set of instructions within braces. You can also specify parameters (inputs). Return values (outputs)....

Contact Us