Throughout the OPT period, you should not be unemployed for 90 days.
For H1B, You can transfer to other companies and you can start for the company as soon as you receive the receipt. It will take a lot of time without premium processing. If you work as soon as you receive the receipt and the transfer is denied, you are out of status unless you can work for the previous company somehow.