How do I test if a specific player is online?

I want to make a command block that detects if me or my friend are online using /execute. How can I accomplish this?


Simply insert their name instead of a selector in /execute if, like this:

/execute if entity Horst run …

This checks if that player exists in the world, which is only the case if they're currently online on that server/LAN game or playing that world in Singleplayer.