August 19, 2009

Javascript Tutorial 12: Break & Continue


var i=0;
for (i=0;i<=10;i++);
{
if (i==5)
{
break;
}
document.write("The number is "+i)
document.write("
");
}


Javascript break skips certain numbers from the list. Remember == is exactly.

This stops numbers from 5 up to 10.

If you only want to skip a certain number from the list, then you would change the code this way:


var i=0;
for (i=0;i<=10;i++);
{
if (i==5)
{
continue;
}
document.write("The number is "+i)
document.write("
");
}

Here you just changed the break to continue and kept everything else the same. The list of numbers will skip 5 and continue up to 10.

Powered by ScribeFire.



No comments:

Post a Comment