The first thing you need to learn is which buildings contain loot - despite having lots of different building types, only a couple of buildings in DayZ are actually enterable, and even fewer of those regularly contain weapons.
Take a look at the DayZ DB Map, some good buildings to look in are
- Office blocks
- "Fire stations"
- Supermarkets
- Barns (particularly the big barns with red rooves)
- "Pubs" - these are not as good for weapons, however very good for bags and the like
- Churches (although less so than the above)
Check the DayZ Wiki or the DB for pictures / common locations of these buildings - recognising which buildings are likely contain loot that you want is very handy and shouldn't take long to learn (there are only a handful of "interesting" building types which contain loot)
When it comes to getting your first weapon there are a couple of different tactics - you can either take it slow, sticking to the outskirts and checking barns and other remote areas, or you can run into the middle of the biggest town you can find straight past all of the Zombies (and possibly players).
My preference is the second option - although unquestionably more risky, in the early stages you have very little to loose, and when it pays off you end up kitted out much much sooner than you would have been if you took it slowly. Initially I played it safe however had exactly the same experience as you - you have absolutely no weapons to start with (not even your fists), and sooner or later you are going to pick up a zombie no matter how careful you are. You might live longer, but you probably aren't any more likely to end up with a gun at the end of it.
Take a look at this video guide for a good root around my favourite city for looting my first weapon. The key to looting the big cities is to get in, get what you need and get out quickly. As soon as you have the basics that you need, get out - the longer you stay in a city, the more likely it is that you will loose your recently earned loot.