Загрузка...

Understanding PHP for Loops in Under a Minute

Loop means repetition or iteration. When a task needs to execute more than once then we call it loop. This code block then wraps with loop and one of such loop formation is called for loop.

Here is how a for loop is written. We are using keyword "for" to create the for loop, followed by parentheses. All the three parts of for loop goes into these parentheses.
for (initialize; condition; increment/decrement)
{
statement 1;
statement 2;
.....
.....
statement N;
}

Let's see an example.
Step 1. Initialization - variable initialize with a value. This part execute at first and only once.
Step 2. Condition - check whether value is less than or equal to 10. This part executes after each increment or decrement.
Step 3. Increment or decrement - increase value by 1. This part executes after each iteration.
Once the condition fails, means value is more than 10, then for loop stops and next line after the loop will execute.
for ($i = 1; $i == 10; $i++) {
echo $i;
}

Видео Understanding PHP for Loops in Under a Minute канала PHP Explained
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять