gap> grp(18);
Group 1 has structure: D18 and is Non-Abelian
Group 2 has structure: C18 and is Abelian
Group 3 has structure: C3 x S3 and is Non-Abelian
Group 4 has structure: (C3 x C3) : C2 and is Non-Abelian
Group 5 has structure: C6 x C3 and is Abelian
The workhorse here is the function ConstructAllGroups and is part of the GAP package GrpConst.
#
# Prints all groups of order n
# IN: Group
#
grp:=function(n)
local listGroups;
listGroups:=ConstructAllGroups(n);
i:=1;
while(i<(Length(listGroups)+1)) do
Print("Group ");
Print(i);
Print(" has structure: ");
Print(StructureDescription(listGroups[i]));
Print(" and is ");
if (IsAbelian(listGroups[i])) then
Print("Abelian");
else
Print("Non-Abelian");
fi;
Print("\n");
i:=i+1;
od;
end;