These kind of questions show that you're still thinking in English.
German has way more grammar flexibility regarding word order than English.
Sometimes nicht is used in a similar manner as in English but sometimes it is at the end of a statement. Sometimes you will see nicht used in both manners, like in this sentence. :)
The key to get used to (and understand) this is to practice it. If your native language has the same grammar flexibility, it can help.
If you've read the conjunction chapter, you'd know. Wenn (if/when) is a conjuction which pushes the verb at the end of the sentence: wenn ich nicht koche
Everytime when there's a conjunction in the first part of the sentence, the second part of the sentence after the comma will always start with the verb: esse ich nicht
This is always a problem for us English speakers, because we have one word which covers multiple concepts, for which German has individual words!
Wann is the when we use interrogatively: ,"wann ist dein Geburtstag?" or any other When...?, such as "when do the shops close?"
"Wenn" is a conditional when, so the simplest way to work out if you should use "wenn" is to try substituting "if". If "if" doesn't work in the sentence(Wenn ,,if" nicht funktioniert...), then "wenn" isn't appropriate. For example, "if I don't cook, I don't eat" -does- work.
A third one is "als" which is -when- in the past. "When I was younger, I had a dog", etc.
I'll try to break it down for you. The most important thing in a German sentence is the position of the verb. Your priority is always to get the verb in its natural place, and then the rest of the sentence follows.
Very simply (I'm over-simplifying!), German verbs either need to be the second idea/concept (not the second word) in a clause or last in a clause. The latter is what we are dealing with here. German conjunctions/connectives are divided into co-ordinating conjunctions (examples: und, aber) which simply join clauses and sub-ordinating conjunctions which drive the verb to the end of the clause.
'Wenn' is a subordinating conjunction, so the 'koche' has to go last in the clause. So nicht simply couldn't follow the conjugated verb, and so it precedes 'koche' instead.
Before you ask, the reason why 'esse' takes the first position after the comma is because 'wenn ich nicht koche' is a subordinate clause, i.e. a sentence fragment.
If you begin a sentence with a fragment that wouldn't make sense on its own, you need a [verb],[verb] arrangement. I always think of sentence fragments as very long subjects in a sentence that follows the most common [subject] [verb] [object] arrangement.
It's a main clause, following a sub-ordinate clause. This explains it well, I think. http://www.bbc.co.uk/schools/gcsebitesize/german/grammar/conjunctionsrev2.shtml
Can someone please help me: do we need to use dativ with the verb kochen or akkusativ? For example, i cook the fish, would it be "ich koche den Fisch" or "ich koche dem Fisch" ? Same question about the verbs warten and kommen, do we need to use dativ or akkusativ with them?