Statement and its type by G Krishna Chauhan

A statement is a command given to the computer that instructs the computer to take a specific action, such as display to the screen, or collect input. A computer program is made up of a series of statements.


  • Decision Making Statements
  • Loop Control Statements 


Decision Making Statements:

Decision making structures require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Type of Decision Making Statements:


  1. if statement
    An if statement consists of a boolean expression followed by one or more statements.

  2. if...else statement
    An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

  3. nested if statements
    You can use one if or else if statement inside another if or else if statement(s).

  4. switch statement
    A switch statement allows a variable to be tested for equality against a list of values.

  5. nested switch statements
    You can use one switch statement inside another switch statement(s).



Loop Control Statements:



You may encounter situations, when a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.

Programming languages provide various control structures that allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of statements multiple times.

Types of Loop:


  1. while loop
    Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

  2. for loop
    Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

  3. do...while loop
    It is more like a while statement, except that it tests the condition at the end of the loop body.

  4. nested loops
    You can use one or more loops inside any other while, for, or do..while loop

No comments:

Post a Comment