HomeVideoPHP

HOW Exactly PHP While, Do-While, For and Foreach Loops WORKS??

HOW PHP While, Do-While, For and Foreach Loops will be WORKS?? this lesson will show you how to use while Do-While, For and Foreach Loops in PHP

#Solved - ERROR Only_full_group_by When Executing a Query in MYSQL
How Does PHP While Do-While For & Foreach Loops Works???
How to Write Good Code & Become a Professional Programmer
How to use While, Do-While, For and Foreach Loops in PHP? Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types.
  1. for − loops through a block of code a specified number of times.
  2. while − loops through a block of code if and as long as a specified condition is true.
  3. do...while − loops through a block of code once, and then repeats the loop as long as a special condition is true.
  4. foreach − loops through a block of code for each element in an array.

Video Tutorial PHP While, Do-While, For and Foreach Loops


The for loop statement

The for statement is used when you know how many times you want to execute a statement or a block of statements.

The example for loop statatement

  <?php
  for ($i=0; $i <5 ; $i++) {
    echo "Display \$i Variable " .$i. "<br>";
  }
  ?>

This for statement results is
Display $i Variable 0
Display $i Variable 1
Display $i Variable 2
Display $i Variable 3
Display $i Variable 4

The while loop statement

The while statement will execute a block of code if and as long as a test expression is true.

If the test expression is true then the code block will be executed. After the code has executed the test expression will again be evaluated and the loop will continue until the test expression is found to be false.

The example while loop statatement

  <?php
  $x=0;
  while ($x < 5) {
    echo "Display \$x Variable " .$x. "<br>";
    $x++;
  }
  ?>

This while statement results is
Display $i Variable 0
Display $i Variable 1
Display $i Variable 2
Display $i Variable 3
Display $i Variable 4

The do...while loop statement

The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.

The example do...while loop statatement

  <?php
  $x=0;
  do {
    echo "Display \$x Variable " .$x. "<br>";
    $x++;
  } while ($x < 5);
  ?>

This do..while statement results is
Display $i Variable 0
Display $i Variable 1
Display $i Variable 2
Display $i Variable 3
Display $i Variable 4

The foreach loop statement

The foreach statement is used to loop through arrays. For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.

The example foreach loop statatement

  <?php
  $x = [0,1,2,3,4];
  foreach ($x as $key => $value) {
    echo "Display \$x Variable " .$value. "<br>";
  }
  ?>

This foreach statement results is
Display $i Variable 0
Display $i Variable 1
Display $i Variable 2
Display $i Variable 3
Display $i Variable 4
Follow us on youtube for more awesome videos and see you next lessons ..

Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


COMMENTS

DISQUS
Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,89,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,6,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: HOW Exactly PHP While, Do-While, For and Foreach Loops WORKS??
HOW Exactly PHP While, Do-While, For and Foreach Loops WORKS??
HOW PHP While, Do-While, For and Foreach Loops will be WORKS?? this lesson will show you how to use while Do-While, For and Foreach Loops in PHP
https://i.ytimg.com/vi/0KqkGkZea6g/hqdefault.jpg
https://i.ytimg.com/vi/0KqkGkZea6g/default.jpg
KODE AJAIB
https://scqq.blogspot.com/2018/10/how-php-while-do-while-for-loop-works.html
https://scqq.blogspot.com/
https://scqq.blogspot.com/
https://scqq.blogspot.com/2018/10/how-php-while-do-while-for-loop-works.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy