ID:1033440
 
(See the best response by Kaiochao.)
Code:
var/i=1
var/a = list(0,0,0,0,0,0)
usr << output("<b>Item</b>","grid:1,[i]")
usr << output("<b>Status/Amount</b>","grid:2,[i]")
i++
for(var/obj/items/sword/S in usr.contents)
if(a[0] == 0)
usr <<output("<b>Swords</b>","grid:1,[i]")
i++
usr <<output(S,"grid:1,[i]")
i++
a[0] == 1
else if(a[0] == 1)
usr <<output(S,"grid:1,[i]")
i++


Problem description:
Basically everything under the if statement gets called but nothing under the else if gets called.

Sorry but I may be confused myself but ..

It won't work like that the for() will stop after it has return each item it won't continue to the elseif because there is nothing left for the for() to do after the first if().

If that makes sense? you'll need a while().
You should be getting a runtime error regarding your attempt to access a bad index. When dealing with numbers in the [] list operator, it accesses the item in the list at that position. Lists only go from 1 to list.len.

Anyway, as for the grid populating, I'm not sure why you even made the 'a' variable. It'd also be nice to see what context this is in to see whether or not you're abusing usr, which is generally done often.

usr << output("<b>Item</b>", "grid:1,1")
usr << output("<b>Status/Amount</b>", "grid:2,1")
usr << output("<b>Swords</b>", "grid:1,2")

var i = 2
for(var/obj/item/sword/s in usr)
usr << output(s, "grid:1,[++i]")
Basically I use the a variable to make sure that the Swords,Guns etc text gets outputed once. I want that text to be put above the actual swords and guns so it be clear what the item is. This code is not the full code but if this can be fixed than the rest will be fixed. The code tries to break up the different types in the inventory and displays them seperately in the grid so similiar types would be together. Anyways I fixed the index error. Also ATHK the loop should run like 10 times because I got put like 10 swords in the inventory. Anyways any ideas on the fix ? Also the list is used because I didnt want to write 6 different variables so that is easier to use.
In response to Dj dovis
Best response
The list (how you're using it) is still unnecessary.
usr << output("<b>Item</b>", "grid:1,1")
usr << output("<b>Status/Amount</b>", "grid:2,1")
var i = 1

if(locate(/obj/item/sword) in usr)
usr << output("<b>Swords</b>", "grid:1,[++i]")
for(var/obj/item/sword/s in usr)
usr << output(s, "grid:1,[++i]")
usr << output("status/amount thing", "grid:2,[i]")

if(locate(/obj/item/gun) in usr)
usr << output("<b>Guns</b>", "grid:1,[++i]")
for(var/obj/item/gun/g in usr)
usr << output(g, "grid:1,[++i]")
usr << output("status/amount thing", "grid:2,[i]")

Of course, you could clean this up by giving items a category variable. Then, a list becomes necessary.
/obj/item
var category = "General"
sword/category = "Swords"
gun/category = "Guns"

// Display the headings
usr << output("<b>Item</b>", "grid:1,1")
usr << output("<b>Status/Amount</b>", "grid:2,1")
var i = 1

// Sort items into their categories
var item_types[0]
for(var/obj/item/item in usr)
if(!item_types[item.category])
item_types[item.category] = list()
item_types[item.category] += item

// Display the categories
for(var/category in item_types)
usr << output("<b>[category]</b>", "grid:1,[++i]")
for(var/obj/item/item in item_types[category])
usr << output(item, "grid:1,[++i]")
usr << output("status/amount thing", "grid:2,[i]")
Thanks that helped me improve the code. I actually found the flaw in my code which made the actual error