Let us trace the execution of the loop step by step:
Iteration i=0:
The original parent process calls fork().
In the parent, fork() returns a non-zero value (the child's PID). Thus, fork() == 0 is false, the parent executes break;, exits the loop, and reaches printf("Hello!");.
In the child (C1), fork() returns 0. The condition fork() == 0 is true, so it executes continue; and advances to i=1.
Iteration i=1:
Process C1 calls fork().
In the parent (C1), fork() returns a non-zero value, it executes break;, exits the loop, and reaches printf("Hello!");.
In the new child (C2), fork() returns 0, executes continue;, and advances to i=2.
Iteration i=2:
Process C2 calls fork().
In the parent (C2), fork() returns a non-zero value, executes break;, exits the loop, and reaches printf("Hello!");.
In the new child (C3), fork() returns 0, executes continue;, and increments to i=3.
Loop Termination:
Process C3 checks the loop condition i<3, which is now false (3<3 is false). It terminates the loop and executes printf("Hello!");.
Hence, exactly 4 distinct processes (the original parent, C1, C2, and C3) reach the printf statement.
Therefore, printf is executed 4 times.