What it means
に行く and に来る express going or coming somewhere in order to do an action. The verb before に is normally its masu-stem, such as 買い in 買いに行く. 行く is used when the movement is away from the speaker's or reference point, while 来る is used when the movement is toward it. The movement verb changes for tense and politeness, but the purpose pattern stays the same.
Usage note
Do not use the dictionary form directly before に for this purpose. For example, 買いに行く is correct, while 買うに行く is not. This に marks purpose, so it should not be confused with the に used to mark a destination.
How to use it
友達が料理を習いにこの町へ来ます。
My friend comes to this town to learn cooking.
私は新しい靴を買いに店へ行きます。
I go to the store to buy new shoes.
友達が料理を習いにこの町へ来る。
My friend comes to this town to learn cooking.
私は新しい靴を買いに店へ行く。
I go to the store to buy new shoes.
