Repetition structures in programming or loops plays an important role in the daily activities of any programmer, with them you can make particular action run repeatedly until it meets a certain condition.

In everyday life, the repetition structures are widely used to verify sequence data and perform actions that would be repetitive. Now meet some of the most used.

WHILE

This repetition structure is one of the simplest, from the verification of certain variable you operate, check its structure below:

While X> 1 Do X = X +1

In this structure we are saying that while the X value is greater than 1 it will have its value incremented (++).

PHP While the structure of the function as follows:

<?php

$var= 0

while ($var <= 10)

{

echo ($var.” “);

$var++;

}

?>

What will be printed is a sequence of numbers 0 to 10. It is important to keep in mind that when you create a loop is necessary to check the parameter that determines its end because there is a risk of an infinite loop that possibly lock the computer case is executed.

DO WHILE

This function works exactly like WHILE, the difference is that it performs the operation and after all the processing works with the condition. Check out the example of this command in PHP as follows:

<?php

$var= 0

do

{

echo ($var.” “);

$var++;

}while ($var <= 10)

?>

FOR

The FOR command is undoubtedly one of the most used, it is possible in a single line of code declare the variable, analyzing the conditional and now realize the increased need for its completion. Check out its structure in PHP:

<?php

for ($var= 0; $var <= 10; $var++)

{

echo ($var.” “);

}

?>

As mentioned above, the infinite loop is an imminent risk when using these types of command, so make sure that the conditional will have a false return is paramount in the construction of syntax.

php

Learn WHILE, DO WHILE and FOR is part of the beginning of the walk of many in the programming world, in addition, choosing a teaching tool and guaranteed return is also part of the process, so know and choose Scriptcase. Thanks to RAD concept implemented in its creation, the encoding time is reduced significantly and with that you get much more in production. Download now the free version of our tool and our e-learning section to learn how to get more from their web applications using our development tool.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.