Cook up something and tell the other person, “Oh, before I go, I just wanted to tell you…” and then wait for the other person to respond. It extends the conversation by maybe a few more words, but lets the other person gently know that you have to leave. Be sure to attentively listen to the other person’s response, and try not to be in a hurry. When the other person has spoken, say goodbye and politely move on, possibly with a handshake or a hug based on the nature of the relationship.
It is a simple, effective way to terminate a conversation. Just ask the other person for the direction to the rest room, and excuse yourself. Once you walk away though, do make a quick visit to the washroom. It would be pretty rude to head over to the bar as the other person watches you.
The best approach to end a conversation is to be direct. Just say “It was a pleasure speaking with you. Thank you for sharing your insight. Enjoy the rest of your evening.” Be sure to shake your hands as you say this, unless you’re holding food/drinks in your hand, and then respectfully move on.
It's important to be polite when ending a conversation. You don't want to leave abruptly and leave a bad taste in your companion's mouth. Instead of walking away randomly, say thank you and nice to meet you. It's a polite way to thank them for the conversation you've had while also signaling that you're ready to move on. You can also add a hand shake if you'd like. Always be respectful when ending a conversation.