fix Issue 7806 - ICE(gloop.c) iterating with idouble, when compiling with -O
refactor duplicate code from elem_print
Merge pull request #2627 from WalterBright/fix7806

fix Issue 7806 - ICE(gloop.c) iterating with idouble, when compiling wit...
Merge pull request #2628 from WalterBright/refactor-elem_print

refactor duplicate code from elem_print