1.

Write the features Looping Structure? Looping Structure:

Answer»

1. Looping Structures are useful for writing iteration logics.

2. It is the most important feature of many programming languages, including PHP.

3. They are implemented using the following categories:

1. For Loop 

2. For each Loop 

3. while Loop 

4. Do while Loop

1. For Loop:

For loop is an important functional looping system which is used for iteration logics when the programmer know in advance how many times the loop should run.

Syntax:

for (init counter; test counter; increment counter)

{

code to be executed;

}

2. For each Loop:

foreach loop is exclusively available in PHP. It works only with arrays. The loop iteration deepens on each KEY Value pair in the Array. For each, loop iteration the value of the current array element is assigned to $value variable and the array pointer is shifted by one, until it reaches the end of the array element.

Syntax:

for each ($array as $value)

{

code to be executed;

}

3. While Loop:

While loop is an important feature which is used for simple iteration logics. It is checking the condition whether true or false. It executes the loop if specified condition is true.

Syntax:

while (condition is true)

{

code to be executed;

}

4. Do While Loop:

Do whileloop always run the statement inside of the loop block at the first time execution. Then it is checking the condition whether true or false. It executes the loop, if the specified condition is true.

Syntax: do

{

code to be executed;

}

while (condition is true);



Discussion

No Comment Found

Related InterviewSolutions