W e b t u t o r i a l s

Define PHP

PHP Installation

PHP INI File

PHP Case Sensitivity

PHP Variable

PHP Echo & Print

PHP Operators

PHP Receiving Input

PHP Decision Making

PHP Loops

PHP Jumping Statement

PHP Image Gallery

PHP Arrays

PHP Date Functions

PHP String Functions

PHP Math Functions

PHP Functions

PHP Variable Scope

PHP Constant Variable

PHP Superglobals

PHP Form Validation

PHP Include Statement

PHP Filter

PHP File Handling

PHP File Upload

PHP Cookies

PHP Session

PHP Send Emails

PHP Captcha

PHP-MySQL Connectivity

PHP MySQL Select

PHP MySQL Insert

PHP MySQL Delete

PHP MySQL Update

PHP Loops

Loops are use to repeat a block of code again and again upto specified number of times. In PHP, there are 4 types of loops available. They are:
for loop.
while loop.
do...while loop.
foreach loop.

PHP For Loop

PHP for loop is divided into 3 parts i.e. initialization, condition and increment/decrement. Initialization is the initial value from where the loop start execution, condition will execute a loop till the specified condition is true and quits the loop if it is false, increment/decrement will change the variable value for the next condition.

Example 1: WAP to print counting 1 to 10 using For Loop
Output

For Loop 1 For Loop 2 For Loop 3 For Loop 4 For Loop 5
For Loop 6 For Loop 7 For Loop 8 For Loop 9 For Loop 10

PHP While Loop

PHP while loop is also used to repeat a block of code up to a certain number of times, but the syntax is different, initialization statement is defined before the loop begins, while loop condition appears to test the loop, and increment/decrement statement will appear inside the while loop.

Example 2: WAP to print counting 1 to 10 using While Loop
Output

While Loop 1 While Loop 2 While Loop 3 While Loop 4 While Loop 5 While Loop 6 While Loop 7 While Loop 8 While Loop 9 While Loop 10

PHP Do While Loop

PHP do while loop is also used to repeat a block of code up to a certain number of times, but the syntax is different, initialization statement is defined before the loop begins, increment/decrement will appear inside the do while loop and condition appears at the last.

Example 3: WAP to print counting 1 to 10 using Do While Loop
Output

Do while loop 2 Do while loop 3 Do while loop 4 Do while loop 5 Do while loop 6 Do while loop 7 Do while loop 8 Do while loop 9 Do while loop 10 Do while loop 11