ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
PHP Tutorial - Index
PHP Tutorial - Introduction to PHP
PHP Tutorial - Your First PHP Script
PHP Tutorial - Operators
PHP Tutorial - Conditional and Looping
PHP Tutorial - Functions
PHP Tutorial - Classes and Objects
PHP Tutorial - Working with Forms
PHP Tutorial - Advanced PHP Topics
PHP Tutorial - Advanced Class Concepts
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > PHP Tutorial > Conditionals and Looping
 

PHP Tutorial - Conditionals and Looping

 
Page 3 of 5
 

Output

Looping

In the previous section you learned about the conditional statements. In this section you will be learning about the looping structures. The looping statements are used to execute a same block of code a specified number of times.

The various looping statements available in PHP are:

While – it loops through a block of code if a specific condition is true and it comes out of the loop only when that condition becomes false.

Do while – in this it loops through a block of code at least once, then it checks for the condition and loops as long as that condition is true.

For – it loops through a block of code a specified number of times.

Foreach – it loops through a block of code for each element in an array.

While Loop

The “while” loop, is the simplest type of loop in PHP. They work the same in PHP as they do in other languages. The “while” statement executes a block of code if a specific condition is true and it comes out of the loop only when that condition becomes false.

Syntax

while (condition)

code to be executed;

 

In the following example we are using the while loop which checks for the condition and executes the loop till the condition is true.

Example

<html>

<body>

 

<?php

$a=1;


while($a<=4)

{

echo "Welcome to floor " . $a ."<br/>";

$a++;

}

?>

</body>

</html>

 

Output:


 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2015. All Rights Reserved.