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 the input text box to not be modified by the user?
checked="checked" readonly="readonly" disabled="disabled"
<input type="text" value="fixed-value" readonly="readonly" name="a_name" />
What CSS property allows you to create rounded corners in your webpage design?
background-size border-size border-radius
.class {
  border:2px solid blue;
What instruction displays a confirmation dialog box to the viewer, who must then click OK or Cancel to proceed?
indexOf() confirm() prompt()
var ques = window.confirm("The result of 0+0 is 0?");
if (ques) alert("Corect");
else alert("Incorrect");
Indicate the PHP function that returns the lowest number of the parameter values.
floor() ceil() min()
$min_nr = min(12, 8, 25, 13);
echo $min_nr;        // 8
While loops

Last accessed pages

  1. CSS Course - Free lessons (20471)
  2. Wake Up! (14391)
  3. JavaScript Course - Free lessons (29685)
  4. The Four Agreements (1040)
  5. PHP-MySQL free course, online tutorials PHP MySQL code (66106)

Popular pages this month

  1. PHP Unzipper - Extract Zip, Rar Archives (94)
  2. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (58)
  3. JavaScript Course - Free lessons (45)
  4. SHA1 Encrypt data in JavaScript (44)
  5. Read Excel file data in PHP - PhpExcelReader (38)