Jonathan's correct. I'll just expand a bit on the "hopefully" note after the second Office Action.
You can get more than just two Office Actions, so you can budget accordingly.
A second Office Action is quite often made "final". At that point, your options are limited. You can appeal, file a Request for Continued Examination (RCE), or abandon the case. There are other avenues, but one finds oneself limited to these three most of the time.
Appeal can cost $3-5k or more in filing the Notice, the Appeal Brief, and a Reply Brief. The appeal can take 5 years or more, although I've recently heard that backlog has been reduced dramatically down to about 2 years. The result of the appeal can be allowance, rejection on the grounds asserted by the examiner in the second Office Action, or new grounds for rejection -- and each can apply to each claim independently of the others. So, your case can get split up and you might find yourself back in regular examination again, repeating the whole process.
RCE costs about one basic filing fee and about an hour of attorney time. In addition, the RCE should be accompanied by a response to the second Office Action, another $1-3k.
I think you'll note a bit of circularity in the process, meaning that you can see loops in the process -- e.g., Office Action, response, final Office Action, RCE/response, Office Action, response, etc. Hopefully, care is taken to make the process end at some point. I believe someone somewhere on the web has a patent prosecution flowchart. You might search for that with your favorite web search tool.
You had asked about pitfalls to avoid at each step of the way. Unfortunately, that is a topic that could easily fill a book or two. It may sound self-serving, but the only way I can think of to avoid the vast majority of the pitfalls is to hire someone who's done this full time for the past several years and who learns from their mistakes -- i.e., hire a good patent practitioner. You might try a book like Patent It Yourself, but there's no guarantee that the book will include all potential pitfalls or that simply reading the book will make you skilled in recognizing the pitfalls as you do your own work.
I hope that helps.