What is the difference between them? Can they be used inter-changeably?
Note that "What for?" is informal/conversational.
"What Purposeful Reason?"
"What for" denotes a purposeful reason, while "Why?" can be used for causes, reasons, or explanations.
- Statement 1: "I am going to work now."
- Why? (Explanation): "Because it's time for me to leave."
Why? OR What for? (Purpose): "To make money."
Statement 2: "Things fall."
- Why (explanation): "Because of gravity..."
- Why (Purpose): "Because of gravity." / "No, I mean, why is it like that? Why is there gravity?" / "Who knows? That's just the way it is. God? Quantum Multiverse? That may not be answerable."
What for (purpose only!): "Who knows? God? Quantum Multiverse? That may not be answerable."
Statement 3: "I exist."
- Why (Explanation/Cause): "Because your parents had sex, your mother got pregnant, and you were born."
- Why OR What for? (Purpose): "In order to propagate the species." OR "For God's mysterious reason." OR "Nobody knows." OR "There is no purpose; it's a quantum multiverse."
Variations can be created by sentences like "What is $NounPhrase$ for?" For example, if one is in a new car with a salesman, one can ask "What is that button for?" In this case, the question is asking for the functional purpose of the button. Also, "What is math good for?" is asking for suitability for a purpose.
"What for!?" -- Emphasis / Surprise / Suspicion
"What for" can lend itself to more emotion than a simple "Why", adding surprise, suspicion, or just more emphasis. In this case, "what for" can be asking for an explanation just like "why":
- Statement 4: "I am going to work now."
- What for!? You just got home! (Surprise/Explanation): / "Because I left my wallet there."
The emotion behind "What for?" can also be suspicion or interrogation. There can be a bit of eye squinting or head tilting:
"Can I ask you your name?"
"Ummm. What for?" (Suspicion)
"For what?" -- Identifying ambiguity.
"What for" can also be used to mean "For what?" in order to identify an ambiguous reference. The emphasis is on replacing the "what" with the named item rather than replacing the "for" with the named reason:
- "I'm looking for something." / "For what?" / "For my glasses."
- "I'm looking for something." / "What for?" / "My glasses." (Same as "For what")
- "What are you looking for?" / "My glasses."
Here's another one:
- "I need some help." / "What for?" / "To reach that top shelf." / "Ok, what for?" / "That coffee mug."
Both "what for" questions could be asking for purposeful reason. For example, in the 2nd case, the reason could have been to clean the shelf. But the answer given in the 2nd case was an identification of the object desired.
Also, "What am I responsible for?" is asking for identification of responsibilities. It is like "For what am I responsible?", but the fronted what sounds more natural.
Why asks about a reason, what for about a purpose.
The distinction is not always clear, but a reason is the cause of something, and a purpose is the result of something.
Why are you wet? Because it is raining.
It would not make much sense to assume someone intended to get or be wet for a specific purpose, so I assume that something caused the person to be wet. Hence, I ask why.
The question asked here is not "what causes war to be a good thing?", but "what purpose does war serve?".