WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

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

1Accespted Javascript 'Do while' Statement Thu Mar 22, 2012 7:51 pm

Mr.Joker

Mr.Joker
Mr. WebArtz
Mr. WebArtz
Javascript 'Do while' Statement
Working with 'do while' statement in javascript


Hello again, I am Mr.Joker and today I will show you how ot use Do while loop. Its all simular but hey, there is difference. Here is code example.

Code:
<script type="text/javascript">
x = 5;
do{
document.write("Number " + x + "<br />");
x++;
} while(x<20);
</script>

Here we have a variable with value 5. I say do (because i want some code be preformed) and I want to write number + variable x. With x++ it mean variable x will be increased. Then i add while(x<20) which mean while x is less then 20 you preform this code. While here basicly say how long this code will be preformed. If i say something like:

Code:
<script type="text/javascript">
x = 21;
do{
document.write("Number " + x + "<br />");
x++;
} while(x<20);
</script>

Now variable x is 21 at start and its larger then are condition. So should it run? Yes it should, but only once. With do code we say preform this code no mather is it true or not. Better example can be seen with boolean type:

Code:
<script type="text/javascript">
do{
alert("I love WebArtz");
} while(0);
</script>

Here i said , preform this alert code as long as its false. But its false so it cant be preformed. But with do code it will be preformed only once and then stop. Thats the point of do while loop.

Notice : These tutorials are copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators.

2Accespted Re: Javascript 'Do while' Statement Tue Apr 03, 2012 12:20 pm

ankillien

ankillien
Administrator
Administrator
Tutorial Accepted

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