Javascript Course

A while loop just looks at a short comparison and repeats until the comparison is no longer True.

The while() loop

The while() loops executes a code as long as a condition is True. If the condition starts out as false, the statements won’t execute at all.

- Syntax:
 //code to be executed
var i =0;
 document.write('<br /> i = '+i);
- First it's declared a variable 'i' with the value of 0. The 'while' statement checks the condition (here: i<5), which it's True and permits the execution of block code inside the brackets. The 'i++' increments the value of 'i' and check again the condition. The loop will stop when the 'i' reach 5.

do ... while() loops

The do...while() loop is a variant of the while() loop. First it is executed the block of code, and then it will repeat the loop as long as the specified condition is true.

do {
 //code to be executed
Here is a simple example:
var x = 8;
do {
 document.write('<br> x = '+x);
- This example display 'x = 8'.
As you can notice, although the condition is false (x<5), the code between braces is still executed once.

Daily Test with Code Example

What attribute makes an option from <select> selected?
checked="checked" selected="selected" disabled="disabled"
<select name="a_name">
 <option value="val1">Option 1</option>
 <option value="val2" selected="selected">Option 2</option>
What CSS value allows to create color gradients for background?
contain repeat-x linear-gradient
#id {
  background: linear-gradient(top left, #1f1, #fff, #11f);
What statement creates an array in JavaScript?
[] {} new Object()
var arr = [1, "", ""];
Indicate the PHP function used to redirect to other page.
function() header() switch()
While loops

Last accessed pages

  1. List with JavaScript events (338)
  2. querySelector and querySelectorAll (20647)
  3. PHP Method Chaining (2975)
  4. $_GET, $_POST and $_REQUEST Variables (31152)
  5. Select in MySQL, Output results in HTML Table (15414)

Popular pages this month

  1. PHP Unzipper - Extract Zip, Rar Archives (31)
  2. SHA256 Encrypt hash in JavaScript (14)
  3. Get and Modify content of an Iframe (13)
  4. Create simple Website with PHP (12)
  5. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (11)