IntelliJ IDEA makes it very easy to surround a code block with if, while, for and other statements or to make a code block become part of such statments as try/catch or synchronized. Simply select the code block to surround (don't forget to use Ctrl + W to increase the current selection) and then press Ctrl + Alt + T (or right-click the selection and select Surround with... from the menu). IntelliJ IDEA will show a list of options to choose from.
Once you have made your choice, IntelliJ IDEA will add the necessary code and put the caret to the position that allows you to complete the surround
Surround With…
by