Spoilers ahead for the Game of Thrones series finale. Game of Thrones ended with Bran Stark sitting atop the Iron Throne — or whatever throne will be built to replace the pointy chair that served as the seat for the most powerful person in Westeros. A lot of people had to die for the seemingly omniscient Bran, who is now the Three-Eyed Raven, to ascend to the position of King of the Six Kingdoms, which begs the question — did Bran know that he was going to become king, and if so, couldn't he have prevented all those deaths?
Bran is weird, and he has been ever since his internship at the cave of the former Three-Eyed Raven. By his own insistence, it's not really Bran who is weird, it's the Three-Eyed Raven who now inhabits the body that used to belong to Bran Stark and seems to carry similar familial allegiances to Bran Stark and is happy to take on the title King Bran the Broken when offered it. Despite the confusion regarding names, Bran is, according to Tyrion, the person (?) with the most interesting story in all of Westeros, which apparently qualifies you to become king. The power of greensight has its limits, however, and while Bran is a living encyclopedia of everything that has ever been witnessed and remembered in all of Westeros, one thing he can not do is set his sights to the future and learn what happens before it happens — at least, not with certainty.
Bran's greensight does allow him to see the future, but it manifests in visions and cryptic clues, as seen in his Season 4 vision of a dragon flying over King's Landing, which finally came true in Season 8. So Bran may have, at some point, seen something that suggested he would become the king, but although the entire history of Westeros is stored in his personal DVR, he cannot skip ahead and see what happens at the end of the episode.
But if Bran can't directly discern the future, why is he always doing things like sitting in the center of Winterfell and saying he's "waiting for an old friend" or responding with an inquiry about whether or not he'd care to be King of Westeros by saying "Why do you think I came all this way?" The first can be explained by Bran's ability to view the present from any perspective, which allowed him to see that Jaime was heading towards Westeros. As for that ominous, "Why do you think I came all this way," however, it may just be Bran playing at the idea of destiny, or saying that he came all this way to be useful in whatever way would benefit the Realm. There's also a chance he just said that because he's weird, which seems to be the reason he says a lot of the things he says nowadays. While Bran may not have known he would be King of Westeros in the end, he clearly had a suspicion that he needed to stick around to perform some important duties — but it seems the show ended before viewers got to see just what those duties would entail.