PDA

View Full Version : The variable seems right, but...



Rain Lover
01-28-2011, 04:41 PM
Hi,

The following loop works:


<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>

But the following doesn't:


<html>
<body>
<script type="text/javascript">
var i=0;
var x="i=0;i<=5;i++"
for (x)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>

I'd just like to create a simple variable.
Please bear with me as I'm a newbie in JavaScript and let me know what I'm missing.

Many thanks in advance!
Rain Lover

vwphillips
01-29-2011, 10:23 AM
x is a string variable which can not be used in the for next loop