SlideShare a Scribd company logo
Control Structure in
JavaScript
By - Bansal Shrivastava
UID - 22MSM40112
Section - MSD-3
What is JavaScript
JavaScript (JS) is a light-weight object-oriented programming language
which is used by several websites for scripting the webpages. It is an
interpreted, full-fledged programming language that enables dynamic
interactivity on websites when applied to an HTML document.
Control Structure
Control structure actually controls the flow of execution of a program. Following
are the several control structure supported by javascript.
❖ if … else
❖ switch case
❖ do while loop
❖ while loop
❖ for loop
If … else
The if statement is the fundamental control statement that
allows JavaScript to make decisions and execute statements
conditionally.
Syntax
if (expression){
Statement(s) to be executed if expression is true
}
Switch case
The basic syntax of the switch statement is to give an expression
to evaluate and several different statements to execute based on
the value of the expression.
Syntax
switch (expression) {
case condition 1: statement(s)
break;
case condition 2: statement(s)
break;
...
case condition n: statement(s)
break;
default: statement(s) }
Do while Loop
The do...while loop is similar to the while loop except that the
condition check happens at the end of the loop. This means
that the loop will always be executed at least once, even if the
condition is false.
Syntax
do{
Statement(s) to be executed;
} while (expression);
While Loop
The purpose of a while loop is to execute a
statement or code block repeatedly as long as
expression is true. Once expression becomes false,
the loop will be exited.
Syntax
while (expression) {
Statement(s) to be executed if expression is true
}
For Loop
The for loop is the most compact form of looping and
includes the following three important parts −
Expression 1 is executed (one time) before the execution of the code block.
Expression 2 defines the condition for executing the code block.
Expression 3 is executed (every time) after the code block has been executed.
Syntax
for (initialization; test condition; iteration statement){
Statement(s) to be executed if test condition is true
}
switch (expression) { case condition 1: statement(s) break; case condition 2: statement(s) break; ... case condition n: statement(s) break; default: statement(s) }
Syntax
do{
Statement(s) to be executed;
} while (expression);
while (expression){ Statement(s) to be executed if expression is true }
Syntax
for (initialization; test condition; iteration statement){ Statement(s) to be executed if test condition is true }

More Related Content

PPTX
Control Structure in JavaScript (1).pptx
PPTX
web presentation 138.pptx
DOCX
Janakiram web
PPT
Control statements
PPTX
DECISION MAKING AND BRANCHING - C Programming
PPT
control-statements, control-statements, control statement
PPTX
Do While Repetition Structure
PPTX
C language 2
Control Structure in JavaScript (1).pptx
web presentation 138.pptx
Janakiram web
Control statements
DECISION MAKING AND BRANCHING - C Programming
control-statements, control-statements, control statement
Do While Repetition Structure
C language 2

Similar to Bansal presentation (1).pptx (20)

PPTX
Constructs (Programming Methodology)
PPT
_Java__Expressions__and__FlowControl.ppt
PPT
_Java__Expressions__and__FlowControl.ppt
PPTX
Flow of control C ++ By TANUJ
PPT
2. Control structures with for while and do while.ppt
PDF
Control flow statements in java web applications
PPTX
PPTX
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
PPTX
Control statements in java
PPTX
2nd year computer science chapter 12 notes
PDF
Loops and conditional statements
PDF
Learn C# Programming - Decision Making & Loops
PPS
Programming in Arduino (Part 2)
PPT
control-statements....ppt - definition
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
PPTX
Cordova training : Day 3 - Introduction to Javascript
PDF
Unit 2=Decision Control & Looping Statements.pdf
PPTX
BSc. III Unit iii VB.NET
Constructs (Programming Methodology)
_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt
Flow of control C ++ By TANUJ
2. Control structures with for while and do while.ppt
Control flow statements in java web applications
controlStatement.pptx, CONTROL STATEMENTS IN JAVA
Control statements in java
2nd year computer science chapter 12 notes
Loops and conditional statements
Learn C# Programming - Decision Making & Loops
Programming in Arduino (Part 2)
control-statements....ppt - definition
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
Cordova training : Day 3 - Introduction to Javascript
Unit 2=Decision Control & Looping Statements.pdf
BSc. III Unit iii VB.NET
Ad

Recently uploaded (20)

PDF
classification of cubic lattice structure
PPT
Drone Technology Electronics components_1
PPT
SCOPE_~1- technology of green house and poyhouse
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
AgentX UiPath Community Webinar series - Delhi
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PDF
MCAD-Guidelines. Modernization of command Area Development, Guideines
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PPTX
Road Safety tips for School Kids by a k maurya.pptx
PPTX
Glazing at Facade, functions, types of glazing
PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PDF
Introduction to Data Science: data science process
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
Internship_Presentation_Final engineering.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
classification of cubic lattice structure
Drone Technology Electronics components_1
SCOPE_~1- technology of green house and poyhouse
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
AgentX UiPath Community Webinar series - Delhi
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
MCAD-Guidelines. Modernization of command Area Development, Guideines
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
Road Safety tips for School Kids by a k maurya.pptx
Glazing at Facade, functions, types of glazing
Structs to JSON How Go Powers REST APIs.pdf
dse_final_merit_2025_26 gtgfffffcjjjuuyy
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Introduction to Data Science: data science process
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Internship_Presentation_Final engineering.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Ad

Bansal presentation (1).pptx

  • 1. Control Structure in JavaScript By - Bansal Shrivastava UID - 22MSM40112 Section - MSD-3
  • 2. What is JavaScript JavaScript (JS) is a light-weight object-oriented programming language which is used by several websites for scripting the webpages. It is an interpreted, full-fledged programming language that enables dynamic interactivity on websites when applied to an HTML document.
  • 3. Control Structure Control structure actually controls the flow of execution of a program. Following are the several control structure supported by javascript. ❖ if … else ❖ switch case ❖ do while loop ❖ while loop ❖ for loop
  • 4. If … else The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Syntax if (expression){ Statement(s) to be executed if expression is true }
  • 5. Switch case The basic syntax of the switch statement is to give an expression to evaluate and several different statements to execute based on the value of the expression. Syntax switch (expression) { case condition 1: statement(s) break; case condition 2: statement(s) break; ... case condition n: statement(s) break; default: statement(s) }
  • 6. Do while Loop The do...while loop is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false. Syntax do{ Statement(s) to be executed; } while (expression);
  • 7. While Loop The purpose of a while loop is to execute a statement or code block repeatedly as long as expression is true. Once expression becomes false, the loop will be exited. Syntax while (expression) { Statement(s) to be executed if expression is true }
  • 8. For Loop The for loop is the most compact form of looping and includes the following three important parts − Expression 1 is executed (one time) before the execution of the code block. Expression 2 defines the condition for executing the code block. Expression 3 is executed (every time) after the code block has been executed. Syntax for (initialization; test condition; iteration statement){ Statement(s) to be executed if test condition is true }
  • 9. switch (expression) { case condition 1: statement(s) break; case condition 2: statement(s) break; ... case condition n: statement(s) break; default: statement(s) } Syntax do{ Statement(s) to be executed; } while (expression); while (expression){ Statement(s) to be executed if expression is true } Syntax for (initialization; test condition; iteration statement){ Statement(s) to be executed if test condition is true }