 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Advertisements

How SAS implements structured programming constructs
RAPTOR Syntax and Semantics By Lt Col Schorsch
Creating PHP Pages Chapter 7 PHP Decisions Making.
Objectives Using functions to organize PHP code
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
ITC 240: Web Application Programming
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Week 11 Recap CSE 115 Spring Want to write a programming language? You’ll need three things: You’ll need three things: –Sequencing –Selection Polymorphism.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Php. What is PHP? PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on.
The foreach LooptMyn1 The foreach Loop The foreach loop gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error.
Decisions, Loops, and Arrays Achmad Arwan, S.Kom.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
PHP Constructs Advance Database Management Systems Lab no.3.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
Introduction to PHP.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Learning Javascript From Mr Saem
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Scratch: iteration / repetition / loops
CiS 260: App Dev I Chapter 4: Control Structures II.
Ch 7: JavaScript Control Statements I.
Web Programming– UFCFB Lecture 16
Arrays, For loop While loop Do while loop
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Computer Science Core Concepts
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Control Structures Part 1
ICT Programming Lesson 3:
Decisions, Loops, and Arrays
PROGRAM FLOWCHART Iteration Statements.
ASP control structure BRANCHING STATEMENTS
CSC1401 Manipulating Pictures 2
LOOPING STRUCTURE Chapter - 7 Padasalai
Looping and Repetition
Presentation transcript:

 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In PHP, we have the following looping statements:  while  do...while  for  foreach

 The while loop executes a block of code as long as the specified condition is true.  Syntax  while (condition is true) { code to be executed; }

"; $x++; } ?> Output: The number is: 1 The number is: 2 The number is: 3 The number is: 4 The number is: 5

 The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.  Syntax:  do { code to be executed; } while (condition is true);

The example below first sets a variable $x to 1 ($x = 1). Then, the do while loop will write some output, and then increment the variable $x with 1. Then the condition is checked (is $x less than, or equal to 5?), and the loop will continue to run as long as $x is less than, or equal to 5: "; $x++; } while ($x

output The number is: 1 The number is: 2 The number is: 3 The number is: 4 The number is: 5

 The example below sets the $x variable to 6, then it runs the loop, and then the condition is checked. "; $x++; } while ($x

 Output The number is: 6

 The for loop is used when you know in advance how many times the script should run.  Syntax  for (init counter; test counter; increment counter) { code to be executed; }

Parameters:  init counter: Initialize the loop counter value  test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.  increment counter: Increases the loop counter value

 The example below displays the numbers from 0 to 10:  "; } ?>

 Output: The number is: 0 The number is: 1 The number is: 2 The number is: 3 The number is: 4 The number is: 5

 The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.  Syntax foreach ($array as $value) { code to be executed; }  For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.

 The following example demonstrates a loop that will output the values of the given array ($colors): "; } ?>

Output: red green blue yellow