LOLWesta, a social media forum


You are not connected. Please login or register

View previous topic View next topic Go down Message [Page 1 of 1]

1
[#1] Javascript Lesson Empty [#1] Javascript Lesson Wed Dec 24, 2014 3:44 am

LOLWesta


LOLWesta King
Hello there guys, today I'll show some JavaScript tutorial that (might) be useful in the future. Thanks to W3Schools and MDN for being a good reference. Wink




Loop was some useful function, it allows you to run the same code several times but with the different value. JavaScript supports many kind of loop with the different usage, here's the list :

  • for - loops through a block of code a number of times
  • for/in - loops through the properties of an object
  • while - loops through a block of code while a specified condition is true
  • do/while - also loops through a block of code while a specified condition is true


For Loop

For loop is the loop that loops through a block of code a number of times.

Syntax :

Code:
for ([initialization]; [condition]; [final-expression])
  statement

Explanation of syntax:

So, let's get to the example.

Code:

var somevariable = variablename;
for (var i = 0, i < variablename; i++) {
document.body.innerHTML = 'Hello world. This is my first loop, you can call this a test loop';

It will declare the variable i and set the value to zero (0), before checks if the value of variable i is less than variablename and performs the succeeding statements before increasing the value of variable i by 1 after each pass through the loop.

Yep, I'll explain just this, I don't understand about loop and such that much rofl, hope you understand more. Smile Thanks to Mozilla Developer Network and W3Schools for the help.

https://lolwesta.forumotion.com

2
[#1] Javascript Lesson Empty Re: [#1] Javascript Lesson Wed Dec 24, 2014 6:36 am

Tsu


Members
Members
Like this?

Code:
var loop = for (var i = 0, i < 13; i++) {
document.write('This is a test');
}

console.log( loop )

3
[#1] Javascript Lesson Empty Re: [#1] Javascript Lesson Wed Mar 04, 2015 7:16 am

Left


Members
Members
Why did you use comma? You have to use this symbol : ;. If you use commas, then the code will never work forever. Then, don't use W3S as a reference forking place.

Sponsored content


View previous topic View next topic Back to top Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum