Eat the Chocolate Bar

I have a chocolate bar and I need help eating it so you'll be writing a program just to do that.

Explanation

The first line is the input. Examples are separated by an empty line.

7
____
__|__|
|__|__|
|__|__|
|__|__|

6
_______
|__|__|
|__|__|
|__|__|

5
____
__|__|
|__|__|
|__|__|

0

1
____
|__|


Spec

Hopefully the examples clearly specify this challenge but to avoid any possible confusion, here's a spec:

You can have a single optional trailing/leading whitespace

An input of 0 is an empty output.

If the input is even, the top rows looks like:

_______
|__|__|


If it's odd, the top row is:

   ____
|__|


If it's odd and greater than 1, the top rows are:

  ____
__|__|


The following rows are:

|__|__|


until the number of instances of |__| is the same as the input

• What's the output for input 1? Does input of 0 need to be supported? – Doorknob Feb 6 '16 at 17:49
• @Doorknob yes, I've updated the challenge – Downgoat Feb 6 '16 at 17:49
• 1. Can we submit a function? 2. Can we take input from STDIN/function arguments? 3. Do we have to output ONE or ALL itterations? – YoYoYonnY Feb 6 '16 at 18:22
• @YoYoYonnY yes, by default you can (this link answers your second question too). I'm not sure what you mean by iterations. Take a look at the examples, that's all you have to output – Downgoat Feb 6 '16 at 18:24
• Are leading blank lines allowed? – Neil Feb 6 '16 at 18:29

Pyth, 55 bytes

K"|__|"IQ>7<*3%Q2r"3 7_"9?tQjb+XW%Q2J+KtKZd*/tQ2]J+*3dK


This is really quick and dirty, written on my phone. Will get to more golfing later.

Haskell has never been great for code golfing...

b="\n|__|__|"
h="   ____\n "
f 1=h++"  |__|"
f 2="_______"++b
f 3=h++"__|__|"++b
f n=f(n-2)++b
f _=""

• It depends on how you look at it. Java > Python > Haskell > GolfLang. I use python ;) – J Atkin Feb 6 '16 at 23:09
• @JAtkin Well look at my PHP answer, then you see what's like worst – timmyRS Feb 6 '16 at 23:10

JavaScript ES6, 80 bytes

x=>(x%2?   ____
${x<2?" ":"__"}|__|:x?"_______":"")+ |__|__|.repeat(x/2)  Uses the same technique as my Japt answer, and is surprisingly not much longer... C, 104 102 bytes f(x){x?x%2?printf(" ____\n%3s|__|\n",x<2?"":"__"):puts("_______"):0;for(x/=2;x>0;x--)puts("|__|__|");}  Maybe I can use some printf trickery to improve this... Apparently I can 𝔼𝕊𝕄𝕚𝕟, 53 chars / 67 bytes ï%2? ⟮__⟯Ⅰ ⦃ï<2?⍞ :⍞Ⅰ⦄|Ⅰ|:ï?⍘_ď7:⬯⦄ |Ⅰ|Ⅰ|ď ï/2  Try it here (Firefox only). This is quite similar to the Javascript ES6 answer, even though I found it independently. Explanation to come when I finish golfing. PHP, 134 chars <?$i=$argv[1];if($i>0){echo($i%2===0?"_______\n|__":" ____\n".($i>1?"___":"   "))."|__|\n";echo str_repeat("|__|__|\n",($i-1)/2);}?>  Notes: • PHP was not built for code golfing • I sure had FUN making this snippet • It throws an error if argv is undefined • Any help to short it is appreciated. Retina, 69 bytes r(1?)1$1__|__|¶
^__(?=\D{5}$) ^.$0____¶ \$0
^\D

^1
___
?1
|


Takes input in unary.

Japt, 60 57 bytes

U%2?[S³'_²²RSU¥1?S²:'_²"|__|"]¬:U?'_p7 :P +"
|__|__|"pU/2


Just a basic answer. Can probably be improved. Test it online!