Click here to Skip to main content
14,303,339 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello,
i want to make a program that counts numbers from left to right.
i'm not sure which loops to use and how, i was thinking of using a for loop in a for loop statement that prints to the webpage (document.write();)

What I have tried:

for(var i=0;i <=10;i++){
   for(var i=0;i <=10;i++){
     document.write('the number is: ' + i);
    }
}
Posted
Updated 29-Oct-18 20:07pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Not sure what numbers you exactly want to count, but the total loop count is in your case:

for(var i=0;i <=10;i++){
   for(var j=0;j <=10;j++){
     document.write('the number is: ' + (i + j));
    }
}


Your initial code snipet looks wrong because you use i in the outer and inner loop which means that your loops will never end. You even declare i twice weach means that your runtime environment should throw an error without executing the code...

It would be good if you could explain better what numbers you want to count in order to get a better suggestion on how to count them ...
   
Comments
Eduardo Lane 30-Oct-18 17:54pm
   
hello thanks Dirk for the code but what i want is that when the first loop counts to 10 that the second loop prints 1 until it reaches 10 and that the output is:
1 the number is 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100