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 tag renders as emphasized text, displaying the text oblique?
<strong> <pre> <em>
<p>Web development courses: <em></em></p>
Which CSS property defines the space between the element border and its content?
margin padding position
h3 {
  padding: 2px 0.2em;
Click on the method which returns the first element that matches a specified group of selectors.
getElementsByName() querySelector() querySelectorAll()
// gets first Div with class="cls", and shows its content
var elm = document.querySelector("div.cls");
Indicate the PHP variable that contains data from a form sent with method="post".
if(isset($_POST["field"])) {
  echo $_POST["field"];
While loops

Last accessed pages

  1. JavaScript code and PHP (29596)
  2. PHP PDO - Select query, fetch (23900)
  3. Variables, Comments and trace() (1095)
  4. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (107212)
  5. PHP Image with text on New Lines (1588)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (455)
  2. Register and show online users and visitors (324)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (247)
  4. JavaScript Course - Free lessons (237)
  5. querySelector and querySelectorAll (224)