1. Home
  2. Docs
  3. Web Technology I
  4. JavaScript-Client Side Sc...
  5. Control Statements

Control Statements

Here is the explanation of Control Statements:

  • if Statement
if (condition) {
  // Code to be executed if the condition is true
}
  • if-else Statement
if (condition) {
  // Code to be executed if the condition is true
} else {
  // Code to be executed if the condition is false
}
  • if-else..if-else Statement
if (condition1) {
  // Code to be executed if condition1 is true
} else if (condition2) {
  // Code to be executed if condition2 is true
} else {
  // Code to be executed if none of the conditions are true
}
  • Switch Statement
switch (expression) {
  case value1:
    // Code to be executed if expression matches value1
    break;
  case value2:
    // Code to be executed if expression matches value2
    break;
  // More cases...
  default:
    // Code to be executed if none of the cases match
}
  • for Loop
for (initialization; condition; iteration) {
  // Code to be executed in each iteration
}
  • while Loop
while (condition) {
  // Code to be executed as long as the condition is true
}
  • do-while Loop
do {
  // Code to be executed at least once, then repeated as long as the condition is true
} while (condition);
  • for…in Loop
for (variable in object) {
  // Code to be executed for each property in the object
}
  • for…of Loop
for (variable of iterable) {
  // Code to be executed for each element in the iterable
}

  • break Statement
break;
  • continue Statement
continue;
  • return Statement
return value;

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *