Is it dangerous to connect two output pins together? If I have two output pins, one set high and the other set low with digital or analog write like this

digitalWrite(PIN1, LOW);
digtialWrite(PIN2, HIGH);


and then I short them together using a wire, will current flow through the wire?
You can connect but requires resistor between two pins to limit the current.