Control Structure in JavaScript (1).pptx

796 views 9 slides Jul 11, 2023
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

thanks


Slide Content

Control Structure in JavaScript By - Manish Kumar, Bansal Shrivastava, Abhinav Yadav UID - 22MSM40208, 22MSM40112, 22MSM40138 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 }
Tags