"what for" vs "for what"

Could you tell me what a difference is between what for and for what?

One more thing, Can u tell me which situation should goes with “what for”, which goes with “for what”?

thank you

“What for?” is usually a standalone sentence/question used to express interest in knowing the reasoning behind some action.
“for what” can be used in more complex sentences. You can check out some examples here.