PHP LOOPS
WORKING WITH LOOPS – FOR LOOP IN PHP

PHP Loops

  • PHP Loops perform repetitive tasks such as:
    • Retrieving information stored in databases
    • Sending mails to multiple users
    • Reading contents of an array
  • Loops provided by PHP are as follows:
    • FOR
    • WHILE
    • DO-WHILE
    • FOREACH

Working with Loops In PHP

  • Executes a block of code repetitively
  • Tests the specified condition
    • If true, the statements present in the body of the loop are executed repetitively
    • If false, the loop ends, and the control is transferred to the statement following the loop
  • The continuous execution of statements inside the loop is called iteration

FOR LOOP In PHP

  • For loop executes block of code repetitively for a fixed number of times
  • Statements in the loop body are executed as long as the condition is satisfied
  • Stops the execution only when the condition is not satisfied

WHILE LOOP In PHP

  • Validity of the condition is checked before the loop is executed:
    • If condition is true, statements are executed in the loop body
    • If condition is false, the body of the loop is not executed
  • The condition is the test expression consisting of variables and operators
WHILE LOOP In PHP

Do-while Loop In PHP

  • Condition is checked at the end of the loop .
  • Executes the loop body at least once .
  • Works similar to the while loop
Do-while Loop In PHP

Jump Statements In PHP

  • Jump Statements control the execution of the loop and conditional statements
  • PHP provides the following jump statements:
    • break
    • continue
    • exit
JUMP STATEMENTS – BREAK, CONTINUE AND EXIT IN PHP

Break Statement In PHP

  • Creak statement stops the execution of the loops and conditional statements
  • The control is then transferred either to the beginning of the next loop or to the statement following the loop
  • Can be used with the if statement, switch statement, for loop, while loop, and do-while loop.

Continue Statement In PHP

  • Continue statement used within the loop statements
  • Skips the code following the continue statement in the loop body and executes the next iteration of the loop
  • Can be used with the if statement, for loop, while loop, and do-while loop

Exit Statement In PHP

  • Exit statement stops the execution of the loops and conditional statements
  • When exit statement occurs program will exit.

Download Notes Of This Blog From the link given below

https://www.mediafire.com/file/73oxng8gzu581bm/LOOPS+IN+PHP.pptx/file

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *