JS-Loop and If
<Beginner JS><Function><Variable><Loop-If><OOP>
if statement
if(MemberAge<18){
document.write("teen");
}
if..else
if(MemberAge<18){
document.write("teen");
}
else{
document.write("big");
}
if...else if...else
if(MemberAge<18){
document.write("teen");
}
else if(MemberAge>18){
document.write("adult");
}
else{
document.write("just 18");
}
Switch statement
Ex1:
switch(memcat){
case1:
Fee=100;
case2:
Fee=150;
case3:
Fee=300;}
case1:
Fee=100;
case2:
Fee=150;
case3:
Fee=300;}
Ex2: with break
switch(memcat){
case1:
Fee=100;
break;
case2:
...;
case1:
Fee=100;
break;
case2:
...;
}
Ex3: no matching than default case
switch(memcat){
case1:
Fee=100;
break;
case2:
...;
case1:
Fee=100;
break;
case2:
...;
default:
Fee:400;
}
Counting and Looping
Executing a portion of code over and over again until an intermediaite condition accurs
For statement
Used as counter
Syntax:
for(start;condition;expression)statement
Ex:
var Number;
for(Number=0;Number<=10;Number++)
document.write("Num"+Number+"<br />");
While statement
Pre execution test is done
Syntax:
while(condition)statement
Ex:
var (Number=0);
while (Number<=8){
document.write("Num"+Number+"<br />");
Number++;
}
//012345678
Do While statement
Syntax:
Do statement while condition
Ex:
do{
document.write("Num"+Number+"<br />");
Number++;
}
while (Number<=8)
//012345678
Comments
Post a Comment