Create a reversed for loop in JavaScript

Description

The following code shows how to create a reversed for loop.

Example


<!--  w  w  w .ja va 2  s  .  c o  m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
for (x = 10; x >= 0; x = x - 2)
{
document.write(x+"<br/>");
}


</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Create a reversed for loop in JavaScript