The reason is that the pipes create sub processes. Use input redirection instead and it should work
#!/bin/bash
while read -r line
do
echo "$line"
while read -r another
do
if grep -i "$another" <<< "$line" ;then
echo "!!!!!!!!!!"
exit 0
fi
done < file2.txt
done < file1.txt
In the general case, where the input comes from another program and not from a file, you can use process substitution
while read -r line
do
echo "$line"
while read -r another
do
if grep -i "$another" <<< "$line" ;then
echo "!!!!!!!!!!"
exit 0
fi
done < <(command2)
done < <(command1)