What are the three main parts of a for loop in PHP?
The three main parts are: 1. Initialization (runs once at the start) 2. Condition (checked before each loop iteration) 3. Increment/Decrement (runs after each iteration)
Click to reveal answer
beginner
Explain the order of execution in a PHP for loop.
First, the initialization runs once. Then, the condition is checked. If true, the loop body runs. After the body, the increment/decrement runs. This repeats until the condition is false.
Click to reveal answer
beginner
What happens if the condition in a for loop is false at the start?
The loop body does not run at all. The program skips the loop and continues after it.
Click to reveal answer
intermediate
Can the increment part of a for loop be empty in PHP? What does that mean?
Yes, it can be empty. This means no automatic change happens after each iteration. You must manually change the loop variable inside the loop body to avoid infinite loops.
Click to reveal answer
beginner
Show a simple PHP for loop that prints numbers 1 to 5.