looping
1. define loop-conditional loop is undefined loop {while , do, for}
2.undefined loop-it is used to excuted continue in a program {for (;;)}
1]. while loop:
Q. what type of variable are used in loop ?
ans- looping is used to counter(i=i+1) variables.
# looping
syntax
while(condition)
{.........logic......}
#loop direction
1.clock wise(while, dowhile)
2. anticlock wise( )
ex.<html>
<head>
<script language="JavaScript" >
var i=1;
while (i<=10)
{
document.write(i+"<br>");
i=i+1;
}
</script>
</head>
</html>
Q. what is property of while loop?
ans it is used to enter control property.
2]. do while loop:<clock wise loop>
this is called exist control loop bcoz is check the condition after the statement.
dowhile loop return only 1 result if the condition is false.
syntax:
do
{
statement;
} while(cond);
ex.
<html>
<head>
<script language="JavaScript">
var i=1;
do {
document.write(i+"<br>");
i=i+1;
}
while(i<=10);
</script>
</head>
</html>
Disadvantages of while and do while
in both the loop its requires multiples lines to execute the code
# for loop-
1. single line loop
2. this is also called as multiple part rules..
there are 3 part
i. initializing
ii. condition
iii. Increment/decrement
Comments
Post a Comment