Lesson 11: JavaScript Control and Loop Structure

Cards (14)

  • Control and Loop - refer to essential elements of programming that developers to manage the flow of a program and execute tasks efficiently.
  • JavaScript Control - used to control the execution of a program based on a specific condition. If the condition is met, then a particular block of action will be executed otherwise it will execute another block of action that satisfies that particular condition.
  • JavaScript includes if/else conditional statements to control the program flow.
  • JavaScript If/Else Statements:
    • If Statement
    • If Else Statement
    • Else If Statement
  • If Condition - use if conditional statement if you want to execute something based on some condition.
  • Else Condition - use this statement when you want to execute the code whenever the condition evaluates to false.
  • Else If Condition - use this condition when you want to apply second level condition after if statement.
  • JavaScript allows multiple else if statements also.
  • Switch Statement - is used for decision-making. It evaluates an expression, matches the expression's value against a series of case clauses, and executes the statements associated with the matching case.
  • JavaScript Loop - are powerful tools for performing repetitive tasks efficiently. They execute a block of code again and again while the condition is true. They are used to execute a block of code repeatedly based on a condition.
  • JavaScript Loop Statements:
    • For Loop
    • While Loop
    • Do While Loop
  • For Loop - used when the number of iterations is known before entering the loop.
  • While Loop - used when the number of iterations is not known beforehand. It continues to execute as long as the specified condition is true.
  • Do While Loop - is similar to the while loop, but it guarantees that the code block is executed at least once before checking the condition.