Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts
Original source
23 responses to “Javascript Tutorial – 13 – For Loop”
to get it to increment do this:
var i=0;
for (i=1;i<=10;i+=3) <!— use the =+ after the i and here it will increment by 3 starting from 1 change the value 3 to any number –>
{
document.write(i+"<br>");
}
good
good
How do you increase it by 2,3 or 4?
Yay for buckey!!!
One question. Why do we have to declare the variable i=0 ? What part does that play in the for loop? The (i=0) part of the for loop is already telling js were to begin the loop so why do we still need to declare a variable? Also the loop still works fine without declaring a variable? Thanks
What is the code when you don't know how much loops there will be happening?
if i want to increase by 2, would i put 2 instead of "i"?
Thanks, Bucky
xXxBoltxXx, an easy way to write a string (e.g. Potato) ten times is with a "while loop". Declare "i" as 0. While "i" is less than 10, document write "potato", and on next line… i++
So yeah, 0-10 is 11 times. :-p
Can someone please help me? I don't know how to make JavaScript print out a word (string?) multiple times. For exapmple, to print out "potato" ten times. How do I do that with the 'for'?
for (var i = 1; i>myDick.length; i++) infinite loop
can you do i++; in JavaScript or is that java only?
Your are awesome man!! You have a really good way of breaking things down. I submitted to your channel months ago and you have helped me out more than you can imagine. Thank you so so much!
If you want, you can just use the built in Math object…
Javascript has a built in pow(args1, args2) method…
But if you want to just use the power of an integer manual for best programming practices, let me know…
long Thanks 😀
gonna fail my web class soley, because of this.
what is the purpose of a loop like this?
I'm studying IT in uni, and the lecturers are close to hopeless. Thanks for the help, your tutorials are the reason I'm getting high distinctions man!
how do i create a loop to find the power of an integer?like to find what is 3 to the power of 3
You are my savior.
guys! i need help im writing a program for practice that does the function of ! on your calc (for those who don't know if you hit !5 it will do 5*4*3*2*1) anyways the way im doing it is that it runs a for loop that subtracts 1 from original number each time it runs until it hits zero. inside the loop i have total = total*number. this works fine and the total adds up. but i want to use the variable total outside of the loop but it doesnt recognize it as a variable…