Java script supports control statements.They are:
- Conditional Statements(If,if …else,if…else…if,switch)
- Loop statements/Iterations(For loop,While loop)
Syntax for If statement:
if(condition)
{
document.write(“statement”);
}
Syntax for if…else statement:
if(condition)
{
document.write(“statement”);
}
else
{
document.write(“statement”);
}
Syntax for else if statement:
if(condition)
{
document.write(“statement”);
}
else if(condition)
{
document.write(“statement”);
}
else(condition) //here we may or may not write condition
{
document.write(“statement”);
}
Syntax for Switch statement:
switch(variable)
{
case outcome 1:
{
document.write(“…..”);
break;
}
case outcome 2:
{
document.write(“…..”);
break;
}
default:
{
document.write(“…..”);
}
}
Break:
Writing the break inside the control structure will cause the programme to jump end of the block.Control statement resume after the block,as if block had finished.
Example to explain above(If statements…)
Output:
Example to explain about Switch Statement:
Output:



