Bạn đang xem: Php implementation of tarjan's cycle detection algorithm
PHP For Loop
The above code outputs “21 is greater than 7” For loops For... Loops execute the block of code a specifiednumber of times. There are basically two types of for loops; for for… each.Let’s now look at them separately. For loop It has the following basic syntaxHERE, “for……” is the loop block “initialize” usually an integer; it is used to lớn set the counter’s initial value. “condition” the condition that is evaluated for each php execution. If it evaluates khổng lồ true then execution of the for... Loop is terminated. If it evaluates to lớn false, the execution of the for... Loop continues. “increment” is used khổng lồ increment the initial value of counter integer.How it worksThe flowchart shown below illustrates how for loop in php works

PHP For Each loop
The php foreach loop is used to iterate through array values. It has the following basic syntaxHERE, “foreach(…)…” is the foreach php loop block code “$array_data” is the array variable to lớn be looped through “$array_value “ is the temporary variable that holds the current array tác phẩm values. “block of code…” is the piece of code that operates on the array valuesHow it works The flowchart shown below illustrates how the for… each… loop works
Output:Mary is FemaleJohn is MaleMirriam is Female
While Loop
PHP While loop
They are used khổng lồ execute a block of code a repeatedly until the phối condition gets satisfiedWhen lớn use while loops While loops are used to lớn execute a block of code until a certain condition becomes true. You can use a while loop khổng lồ read records returned from a database query.Types of while loops Do… while - executes the block of code at least once before evaluating the condition While… - checks the condition first. If it evaluates khổng lồ true, the block of code is executed as long as the condition is true. If it evaluates khổng lồ false, the execution of the while loop is terminated.While loopIt has the following syntaxHERE, “while(…)…” is the while loop block code “condition” is the condition to be evaluated by the while loop “block of code…” is the code to be executed if the condition gets satisfiedHow it worksThe flow chart shown below illustrates how the while… loop works
PHP vì chưng While
The difference between While… loop & Do… while loop is do… while is executed at-least once before the condition is evaluated.Let’s now look at the basic syntax of a do… while loopwhile(condition);HERE, “do… while(…)” is the do… while loop block code “condition” is the condition lớn be evaluated by the while loop “block of code…” is the code that is executed at least once by the do… while loopHow it worksThe flow chart shown below illustrates how the while… loop works