Page 326 - Web Applications (803) Class 11
P. 326
case 2: circle_circum=2*3.14*radius;
document.write("Circumference of Circle "+circle_circum+"<br>");
break;
default: document.write("Invalid Choice")
}
</SCRIPT>
</BODY>
</HTML>
2. Write JavaScript code for the following:
• Accept salary and grade from the user. Based on the grade add the bonus to the salary and display net
salary.
Grade Bonus
A 30% of salary
B 35% of salary
C 20% of salary
D 15% of salary
• Write a program using the switch statement to print the names of class teacher of all grades from 1 to 10. hint:
let the grade be a variable. depending on its value, print the names of the class teacher. [CBSE Handbook]
4.17 LOOPING STRUCTURE IN JAVASCRIPT
Sometimes, you need to repeat a task multiple times or you may need to repeat the task either a certain number of
times or until a condition is satisfied. In JavaScript, the statements that are used to repeat a set of instructions are
called iterative or looping statements or simply loops. Loops are very useful and necessary for developing applications.
JavaScript provides four types of loop:
Types of Loops
for for...in while do...while
The for loop
The for statement or loop is used to repeat an instruction or a set of instructions for a fixed number of times. The
syntax to use the for loop is as follows:
for (initialisation_expression; conditional_expression; update_ expression) {
// loop body
}
Here,
Ð Ðinitialisation_expression: In this expression, a variable is initialised which is also known as loop control variable.
This expression is executed only once in a loop.
Ð Ðconditional_expression: This expression contains a logical condition which returns either True of False. If the
condition evaluates to True, the statements written inside the loop body will execute. If the condition evaluates to
False, the statements written inside the loop body will be skipped. Loop will terminate once the condition becomes
False.
Ð Ðupdate_expression: This expression is executed after every pass of the loop. A pass of a loop is known as an iteration.
In this expression, the loop control variable is updated by increasing or decreasing its value.
324 Touchpad Web Applications-XI

