CSS - Practical No.2
CSS - Practical No.2
2 :
b. FOR..IN LOOP: The for/in statement loops through the properties of an object. The block of
code inside the loop will be executed once for each property.
Syntax: for (var in object)
{
//code block to be executed
}
c. WHILE LOOP: If you don’t know the exact number of times your code is supposed to
execute, use a while loop. With a while loop your code executes while a given condition is true;
as soon as this condition evaluates to false, the while loop stops.
Syntax: while (variable <= endvalue)
{
//code to be executed
}
d. DO..WHILE LOOP : This kind of loop is similar to the while loop. The difference between
the two is this: In the case of the while loop, if the test condition is false from the start, the code
in the loop will never be executed. In the case of the do ... while loop, the test condition is
evaluated after the loop has performed the first cycle. Therefore, even if the test condition is
false, the code in the loop will execute once.
Syntax: do
{
//code to be executed
}
while (variable <= endvalue)
III. Result :
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
IV. Conclusion(s)
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
V. Questions:-
1. Explain for loop with an example.
"For" Loop is used to repeat a specific block of code a known number of times.
for (var i = 0; i < 10; i++) {
// some code
}
case value2:
// body of case 2
break;
case valueN:
// body of case N
break;
default:
// body of default
}
VI.. Exercise:-
1. Write a program to display even and odd numbers.