First you have to understand the type casting in C++, basically 0 is false when converted to boolean type (You can see a reference from here: c++ bool question)
Now the program does a very simple thing for each iteration in the loop:
Assign b[i]
to a[i]
and try to cast this int to boolean type (implicit conversion), and see if it is true of false, it prints the integer if it is true, break the loop otherwise
Thus, you can see why the first 3 integer is printed out, as they are assigned to a[i]
, being covnerted to boolean, and turns out they became true (yes, -1 became true as well, all non zero integer will became true when converted to boolean)
The 4th number is 0, and similarily it is cast to boolean and became false! So the execution breaks out the loop, no more looping, no more printing. (Even if the 5th number is non-zero, as the execution leaves the loop already, it won't be printed)