First, I doubt you followed my advice to add breaks and step through your for loop as doing so immediately showed the problem (I think it took me three minutes, and most of that was just figuring out where things were in your code since I didn't write it and what was happening and what was not supposed to be happening). To be honest, I'm tempted to not tell you what it is so that you have to learn how to go through this debugging processes yourself.
There is nothing wrong with the for loops. They are acting exactly as they should. The problem is that they way you have it set up there is no possible way for the final if statement to not be true at some point. The reason for this is very simple - you have two itemID. So in your example oSword is 5 and oTest is 6. So, let's say you're holding a sword - the loop checks to see if global.inventory != global.itemID. It does as oSword is 5 == itemdID[0] which is also 5. HOWEVER, you've put it in a for loop so it loops again and now it checks oSword against itemID[1] which is 6. These aren't equal so it evaluates as true and drops the item. Again, this was very, very easy to see with the debugger and took a single test run once I figured out what I was testing to debug.
A simple fix to see that this is true is to change both itemIDs to 5. You can now no longer drop the sword.
In short, you need to find a different way to check if the inventory item is droppable or not. There are lots of ways to do this. Working with your original idea, though this isn't very optimized it shouldn't matter much, is move the itemID checking inside of the last for loop and iterate through all of the items there. For example in psudo code
Code:
if (you think you should drop it) {
if (global.iventory[I] == any global.itemID) { //either use an or statement for every itemID or use the for loop here
break; //e.g. don't drop
}
}
Or something like that.
Edit: as a side note, I did think the little portion of the game I played was interesting. Or rather that the mechanic of digging and building was simple and cool.