In JavaScript language, the conditional statements are very powerful. There are two main kinds of statements: condition and iteration.
The conditional statements with "if" and "switch" are used in the codes with more than one statements which may happen sequencely or simultaneously. The structures are below:
1. if (condition)
{
statement1;
}
statement2;
2. if (condition)
{
statement1;
}
esle
{
statement2;
}
3. if (condition1)
{
statement1;
}
esle if (condition2)
{
statement2;
}
else
{
statement3;
}
4. switch (expression)
{
case value1: statement1;
break;
case value2: statement2;
break;
case value3: statement3;
break;
default: statement4;
}
The iteration statements are for the statements which may happen many times but doing the same instruction. The structures are below:
1. for (initialization; condition; iteration)
{
statement;
}
2. for (variable in object)
{
statements;
}
3. while (condition)
{
statements;
}
4. do
{
statements;
} while (condition);
When using these kinds of statements, "break;" and "continue;" are working within them to perform two functions: "jump out the whole iteration" and "just jump out this iteration and continue to do another one".
Hi Karen,
回复删除Yes these conditional statements can be very useful. How do you intend of utilising them in your project?
Where did you find this information?