Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Javascript

Conitional Statements

Like in ABAP we have the control statement in JavaScript like

1. If else condition

2. While

3. Do while

4. Switch case

5. For loop

6. For in

IF Conditions:

IF..ENDIF.

Syntax:

if (condition){
//Statements to be executed;
};
Example:

clip_image002

Note: In ABAP we write within if… endif and we don’t have brackets. In Javascript there is no endif, so we need to close the brackets and end the block with semi colon.

IF..ELSE… Condition:

Syntax:

if (condition){
//Statement to be executed;
} else {
// Statement to be executed;
};
Example:

clip_image004

Multiple if..else..condition:

Syntax:

if (condtion) {
//Statements to be executed;
} else if (condition) {
// Statements to be executed;
} else {
// Statements to be executed
};

Example:

clip_image006

Switch Case:

Note : Case statement in ABAP is Switch case in Javascript.

Syntax:

switch (expression)
{
  case condition 1: statement(s)
                    break;
  case condition 2: statement(s)
                    break;
   ...
  case condition n: statement(s)
                    break;
  default: statement(s)
}

Example:

clip_image007

Note: Break statements are important after every case conditions, otherwise the output will be like this.

clip_image009

While Condition:

When we want some statements to be executed again and again until the condition fails we use the while statements.

Syntax:

while (expression) {
//statements to be executed;
};
clip_image011

Do while:

The do while also repeats the execution of statements repeatedly until the condition fails. The difference between do while and while statement are as below.

When condition fails in while statement no execution at all:

clip_image012

In do while even if the condition is not fulfilled the statement gets executed once.

clip_image013

Note: We do not have the do..while in ABAP, instead we have do statements.

For Loops:

For loop is another form of looping. This is similar to that of loop statements in ABAP.

The for loops contains, three major parts:

1. Initialization

2. Condition

3. Iteration

Syntax:

for (initialization; test condition; iteration statement){
     Statement(s) to be executed if test condition is true
}
Example:

clip_image014

For in:

There is one more looping keyword called for..in which is used to loop the JS objects. Since we are not familiar with JS objects as of now skipping this part for now.

About Arun

0 Comments:

Post a Comment

Powered by Blogger.