Usage of に to indicate purpose


I'm trying to understand the use of に as a particle to indicate the purpose of
someone moving to another place to do something. For example, lets say that I
want to say "I'm going home to eat dinner." Would this be written as:

> 私はひるごはんを食べますにうちへ行きます.

Or, if I wanted to say "I went to the library to study."

> 私はべんきょうしますに としょかんへ行きました

Are these correct? And does the particle に always come after the verb
indicating what action is taken?

P.S: I checked the other topics relating to this, but none of them really
cleared up the question I had. So, I'm sorry for posting something similar!




Your understanding of the meaning of に is basically okay, but you must use the
**masu-stem** (aka pre-masu form, 連用形) of a verb before に. Instead of 食べますに or
べんきょうしますに, you have to say 食べに or べんきょうしに.

>   * 私はひるごはんを **食べに** うちへ行きます。
>   * 私は **勉強【べんきょう】しに** 図書館【としょかん】へ行きました。
>

More generally, ～ます/～です is used near the end of a main clause. See: [Use of
-です／-ます in the middle of a complex
sentence](https://japanese.stackexchange.com/q/28666/5010)

