11/6/2023 0 Comments Examples for for loop in php![]() The value of num is 45 and the value of i is 5 The value of num is 46 and the value of i is 4 The value of num is 47 and the value of i is 3 The value of num is 48 and the value of i is 2 Output: The value of num is 49 and the value of i is 1 This example decrements the value of a variable with each iteration of the for loop, while the counter increases until it reaches 10 when the evaluation is false and the for loop terminates. The next pass will then process the next array element. ![]() At each pass, the value of the current array element is put into $value and the array pointer is moved by one. The value of a is 50 & the value of b is 25Īt the end of the loop a = 50 and b = 25 PHP – foreach loop statementĪrrays can be looped through with the foreach statement. The value of a is 40 & the value of b is 20 The value of a is 30 & the value of b is 15 The value of a is 20 & the value of b is 10 Output: The value of a is 10 & the value of b is 5 If the condition is false, we will leave the for loop. If the condition is true, the body of the loop will be run, and then we will go to the update expression. Test Expression: We have to test the condition in this expression.Initialization Expression: In this expression, we need to set some value as the initial value for the loop counter.Each step is done again and again until the exit condition is met. If the statement is true, the loop body is run and the variable in the loop is changed. First, give this loop variable a value, and then check to see if that value is less than or more than the value of the counter. In for loops, the loop is controlled by a loop variable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |