Previous
For Loop 
Next
Function 
ABC of JavaScript : An Interactive JavaScript Tutorial
While Loop

While Loop

Syntax :
while(CONDITION) {
BODY
}

This loop will continuously execute the statements in the body as long as a given condition is true. This loop must be handled with care. Always make sure that the given condition will be met - or this loop will continue forever. Let us see an example with the while loop that uses while loop in a situation very similar to the one given in the for loop example.

This basically displays all the elements in an array - the same thing we did using the for loop. Notice how the while loop differs from the for loop. In the while loop, only the condition will be given inside the while loops parenthesis - '(' and ')'.

Previous
For Loop 
Next
Function 

Comments

Anonymous at 26 Mar, 2008 04:28
I need you to help me with the XML while loop syntax, when using stylus studio

Regards,
Mavula Mabena.
Reply to this.
Ramesh at 08 Nov, 2008 12:55
Hi i am ramesh , i want for loop output
12345 54321
1234 4321
123 321
12 21
11
plz send output



kindly send Urgent
Reply to this.
Anonymous at 09 Mar, 2009 07:21
HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.
Reply to this.
Anonymous at 25 Mar, 2009 10:17
who can help to do this question?
Using function, write a program (you can name the function as read()) which can read one integer value from 1 to 10. Input will stop once the user refuses to enter more integers. (Hint: you can use while or do..while loop). Then write another function (you can name the function as print( )) which print the summation of all the numbers.
Reply to this.
hazwan at 04 Mar, 2010 01:55
A palindrome is a string that is spelled the same way forward and backward.
Some examples of palindromes are: “radar”, “madam”, “tenet”, “kayak”.
Write a function called testPalindrome that returns 1 if the string stored in the
array is a palindrome and 0 otherwise. Use at least one function
Reply to this.
Comment

Please dont enter you comments in this form - this is a fake form to confuse spamming bots. The next form is the real one.




Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.