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

Which HTML5 tag defines marked text? (can be used to highlight parts of text)
<mark> <embed> <span>
<p>Free corses: <mark></mark> for Web Development.</p>
Which CSS pseudo-class adds a style to an element when the mouse is over it?
:focus :hover :active
a:hover {
  font-weight: bold;
  color: #00da01;
Click on the function which returns a string value that represents the number rounded to the x digits after the decimal point.
toPrecision(x) toFixed(x) floor(x)
var num = 12.34567;
num = num.toFixed(2);
alert(num);       // 12.35
Indicate the PHP function which reads an entire file into an array.
[) file() readfile()
$arr = file("a_file.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
While loops

Last accessed pages

  1. SSEP - Site Search Engine PHP-Ajax (9769)
  2. Node.js Move and Copy file (21212)
  3. Dynamic variables in JavaScript (14551)
  4. Area and Perimeter Calculator for 2D shapes (8566)
  5. PHP MySQL - using MySQLi (9139)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (457)
  2. The School for Gods (334)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (225)
  4. Add, Change, and Remove Attributes with jQuery (210)
  5. PHP Unzipper - Extract Zip, Rar Archives (206)