|
..I am sort of confused when it comes to looping.. This tutorial is very good exp. to me.. There's two main kinds of loops, for and while. (There's also a for-each and do-while, but don't worry about them.) A for loop has this format: for( initial statement; continue condition; extra condition){ Executed statement} Initial statement - this is executed once before the for loop is ever ran. This is typically a variable declaration like "a = 0" Continue condition - before each loop in the for, this is checked. The for only continues while this is true. Extra condition - this is executed at the very end of the loop. It's typically an increment (x++) or a decrement (x--) Executed statement - This is the code that is executed for each loop through the for loop. Now for a while loop. A while loop is straight forward. While the continue condition is true, it continues. while( continue condition){ Executed statement} We can express a for loop in terms of a while loop initial statementwhile( continue condition){ Executed statement extra condition} So in essence, they're both very similar. That help any?
|
|
|
|
richardgary1223
Guest
|
..What comes under Initial Statement then?
Like what goes into it?..
|
|
|
|
You mean a for-in? And just because I like to explain things a bit differently, for( statement; condition; operation) { exec code} statement: can pretty much be anything. condition: whatever needs to be true for exec code to run operation: something done so that the condition eventually returns false (stops the loop). Again, statement can be anything. In fact, so can operation. These parameters are really just for convenience. Simple example: for(var x = 0; x < 6; x ++) { alert(x) } The above will declare variable x, run the loop, increment x, and repeat the process of running and incrementing so long as x is less than 6. For the above, we recieve 6 alerts (0,1,2,3,4,5). Same example without the "convenience" var x = 0; for(;x < 6;) { alert(x) x ++ }
|
|
|
richardgary1223
Guest
|
..Oh yes.. I seem to understand it.. --The tuts from here are great,I didn't seem to understand looping in W3Schools..
|
|
|
|
It just takes a bit to understand stuff. Getting different explanations can help greatly. Also, notice Aaron's last example var x = 0; for(;x < 6;) { alert(x) x ++ } This is just like a while also. var x = 0; while(x < 6) { alert(x) x ++ } Exact same amount of characters used too. Aaron: Yeah, for-in. Whoops. All other languages is a for-each. PHP: foreach($arraystuff as $key => $value){ // Blah } Java: int[] arrayHolder = new int[5]; for(int row : arrayHolder){ // Code } Still called a for-each there... so I just used that. Oh well.
|
|
|
|
richardgary1223
Guest
|
SO for 'for' looping:
<script type="text/Javascript"> for (i=1; i <= 8; i++) { document.write(This is " +i); } </script>
|
|
|
|
SO for 'for' looping: <script type="text/Javascript"> for (i=1; i <= 8; i++) { document.write(This is " +i); } </script>
Besides the syntax error, yes, that is correct. The error is this: (You forgot the red) document.write([red]"[/red]This is " +i);
|
|
|
|
|
Are all of the different code types used in one code? Like CSS, HTML, and other codes all used in one code?
|
My Forum I came here to learn how to code for my forum and to share with others[/b]
|
|
|
|
Are all of the different code types used in one code? Like CSS, HTML, and other codes all used in one code? They can be. HTML, CSS, and JavaScript are three separate things that integrate seamlessly. HTML is the markup that places objects and text on the page. CSS is the styling used to pretty things up (colors, positioning, etc.) JavaScript is used to make things dynamic (i.e. if I click "Expand" on the textarea while posting, it expands downward.) For the sake of elaboration, CSS is usually placed either as part of an HTML tag or inside of one. So: <span style="font-weight: bold">Text</span> <style type="text/CSS"> .someSpan { font-weight: bold; } </style> In these cases, CSS is an attribute of an HTML tag or the content of another. So, CSS integrates with HTML. JavaScript is similar... <script type="text/Javascript"> alert("Hello world!"); </script> In this case, JavaScript's code is placed inside an HTML tag again. This one doesn't modify HTML, but it does produce a popup window. It can however directly interact with HTML, much like how we use it on ProBoards. Does that help explain it?
|
|
|
|
|
|
|
|
|
w3schools.com has saved my life a few times...and google in general w3fools.com/
|
|
|
|
|
I needed to read this a few years ago. You plan on writing any tuts for V5 Chris? I may. I want to see what their developer docs cover, once those get published... but those might be quite a ways out still. Probably not until the April deadline, actually. Definitely feel free to ask questions though. I may record myself doing a skin conversion, because that might be helpful.
|
|
|
|