Skip to main content

JavaScript Control Statements | if - if-else if-else Statement - switch Statement in JavaScript

JavaScript Control Statements:

JavaScript control statements are used to manage the flow of a program by making decisions and repeating actions based on conditions. The primary control statements in JavaScript include:

JavaScript Control Statements - if - if-else if-else Statement - switch Statement in JavaScript
JavaScript Control Statements

1. if Statement:

   - The `if` statement is used to execute a block of code if a specified condition evaluates to true.
   javascript
   if (condition) {
     // Code to be executed if the condition is true
   }

2. if-else Statement:

   - The `if-else` statement is used to execute one block of code if a condition is true and another block if the condition is false.
   javascript
   if (condition) {
     // Code to be executed if the condition is true
   } else {
     // Code to be executed if the condition is false
   }

3. if-else if-else Statement:

   - This statement allows you to test multiple conditions and execute different blocks of code based on which condition is true.
   javascript
   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
   }

4. switch Statement:

   - The `switch` statement is used to perform different actions based on different conditions.
   javascript
   switch (expression) {
     case value1:
       // Code to be executed if expression matches value1
       break;
     case value2:
       // Code to be executed if expression matches value2
       break;
     default:
       // Code to be executed if none of the cases match
   }

5. for Loop:

   - The `for` loop is used to iterate over a block of code a specified number of times.
   javascript
   for (initialization; condition; iteration) {
     // Code to be executed in each iteration
   }
   

6. while Loop:

   - The `while` loop is used to repeatedly execute a block of code as long as a specified condition is true.
   javascript
   while (condition) {
     // Code to be executed while the condition is true
   }
   

7. do-while Loop:

   - The `do-while` loop is similar to the `while` loop, but it ensures that the code block is executed at least once before checking the condition.
   javascript
   do {
     // Code to be executed at least once
   } while (condition);
   

8. for...in Loop:

   - The `for...in` loop is used to iterate over the properties of an object.
   javascript
   for (variable in object) {
     // Code to be executed for each property of the object
   }
   

9. for...of Loop:

   - The `for...of` loop is used to iterate over the values of an iterable object (arrays, strings, etc.).
   javascript
   for (variable of iterable) {
     // Code to be executed for each value of the iterable
   }
   

These control statements provide the foundation for managing program flow and implementing various logic structures in JavaScript. They are essential for creating dynamic and responsive applications.

Comments

Popular posts from this blog

Biography of Manohar Joshi

Biography of Manohar Joshi: Manohar Gajanan Joshi is an Indian politician who has played a significant role in Maharashtra state politics. Born on December 2, 1937, in a middle-class family in a village called Ganeshpeth in Ratnagiri district, Maharashtra, Joshi's journey into politics was marked by his association with the Shiv Sena, a right-wing regional political party in India. Joshi's political career began in the late 1960s when he joined the Shiv Sena, which was then led by its founder, Bal Thackeray. He quickly rose through the ranks of the party due to his organizational skills, dedication, and ideological alignment with the party's principles, which advocated for the interests of the Marathi-speaking population of Maharashtra. In 1972, Manohar Joshi won his first election to the Brihanmumbai Municipal Corporation (BMC), marking the beginning of his electoral career. He served as a corporator in the BMC and later became the Mayor of Mumbai in 1976. Joshi's tenu...

Professor Cheiro Prophecies about India | 5 predictions Professor Kiro - Kiro made these amazing predictions for India

Professor Cheiro Prophecies:  Here is Kiro made these amazing predictions for India: Professor Kiro was born in November 1866 in England. At the age of 17, Kiro came to Mumbai and met astrologer Vednarayan Joshi. With his advice, he will reach the Himalayas, Kashmir, Ladakh and Varanasi. From here, he studied astrology extensively. Kiro made many predictions in his life, which we are giving you here. Cheiro, whose real name was William John Warner, was a prominent Irish astrologer and palmist who gained fame in the late 19th and early 20th centuries. He was known for his accurate predictions and was consulted by various prominent figures of his time, including Mark Twain, Oscar Wilde, and Thomas Edison. Cheiro also made some predictions related to India. Parada Kahanee One of his notable predictions about India was made in his book "Cheiro's World Predictions," published in 1926. In this book, he wrote about the possibility of India gaining independence from British...

Merry Christmas Messages and Statuses | History and Celebration Christmas - Happy Christmas Status and Messages for Social Media

Merry Christmas Messages and Statuses: Wishing you a Merry Christmas 2023! Here are some messages and statuses that you can share with your loved ones: "May your Christmas be filled with joy, laughter, and love. Wishing you a wonderful holiday season!". "Sending you warm wishes and good cheer this Christmas. Have a great time with your family and friends!". "May the spirit of Christmas fill your heart with peace and happiness. Merry Christmas!". "Wishing you a magical and blissful holiday season. Have a Merry Christmas and prosperous New Year!". "May this Christmas bring you all the love and luck in the world. Merry Christmas and a Happy New Year!". Wishing you a Merry Christmas 2023 Here are some Christmas messages that you can use to wish your friends and family a Merry Christmas: 1. Wishing you a Christmas filled with joy, love, and laughter. May the spirit of Christmas bring warmth to your heart and happiness to your home. 2. May y...