For centuries flags have been used as a signal to let others know something about the group or individual that is displaying, fying or waving the flag. There are country flags and state flags. Ships at sea few the flag of their country. Pirates few the skull and cross bones. A yellow flag was used for quarantine, usually the plague. Even pirates stayed away. Today, some people might recognize the flag used by scuba divers. The Presidents of most countries have a flag. At a race car event they use the checkered flag to indicate the race is over.
Computer programming uses the concept of a flag in the same way that physical flags are used. A fag is anything that signals some information to the person looking at it.