Controlling program flow - AJAX

PHP contains various structures for controlling the flow of your programs.One of the most useful is the simple if statement, which allows you to alter the flow of program execution depending on the outcome of a condition. Let’s have a look at a code snippet using the if statement:

This if statement simply evaluates the condition contained in the brackets. If the condition is satisfied, the statements within the curly braces are executed;
otherwise, these statements are ignored. We can also add an else clause to our if statement:

PHP also has loop constructs, which allow you to repeat the same code instructions a number of times until the conditions are satisfied for the loop to be terminated.This is the code for a while loop:

The statement $x++ means “increment x by one.”The loop executes over and over until the condition$x<=12is no longer met (because $x has become greater than 12), and the statements within the curly braces will then be ignored. Program execution then carries on from below the closing curly brace. You can also make a similar loop using PHP’s for construct:

The for statement takes an argument with three components. The first is evaluated before the first loop and provides a starting value for $x. The second component of the argument is the condition that will be evaluated on each loop to test whether the loop should be executed, and the third is a statement that will be carried out after each loop, and in this case increments $x.The operation of this loop is identical to that of the while example.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

AJAX Topics