Branching Control Structure in JavaScript

Branch Structure
The concept of branching in programming is similar to the concept of branching on a highway, whose determination of direction is determined based on the purpose of the user. Direction here shows the part of the program to be executed, while the destination is input data that is used branching to make decisions. In general, branching is described as follows
Types of Branching
  1. If
  2. Else If
  3. Else
  4. Switch
Make a branch
If written in the format the program code is stated as follows.

Programmatically fulfilling this condition means that the condition has a true boolean value. The program block to be executed is placed in curly brackets. The following is an example of a program with conditions that will generate true or false according to the input of the given age.

The following are other formats that can be used to accept inappropriate conditions.
For conditions more than one can also be made using the following format.
Switch
Switch is another form of branching. This concept is useful if the conditions to be determined have a certain value. The format of the switches is as follows.
Example of branching, Make a web page as follows
Save the file as percabangan.html


Examples of other programs use if and else

Make a web page as follows.


Save the file with the name branch_ sport.html

Examples of other programs use if, else if and else
Make a web page as follows.
Save the file with the branch name, whatever it is.html



Example of making a travel catapult program

Make a web page as follows.
Save the file as application_travel.html

Use of Switch

Make a web page as follows
Save the file as percabangan_switch.html

In the example program above if the user chooses 1, there will be a message "The amount of your credit is nineteen thousand rupiah" displayed. If the choice is not in the switch-case block, the default part will be executed.

The break statement in the above program is used to exit the selected case or default block. If there is no break, the case block and / or default below it will also be executed.

0 Response to "Branching Control Structure in JavaScript"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel