Conditional command (depending of the arguments)

You can have a variable number of items by rethinking your usage of a tabular and using an inline list.

\documentclass{article}
\makeatletter
\newcounter{inline}
\def\inlinelist#1{%
 \setcounter{inline}{0}%
 \@for\next:=#1\do{%
   \stepcounter{inline}%
   \alph{inline})\thinspace\next\space}
}
\makeatother
\begin{document}
\inlinelist{one,two,three,four,five, six}

\inlinelist{one,two,three}
\end{document}

enter image description here

This is a shorter solution, more flexible and less typing.


You could define a starred and unstarred macro so that \mytabs uses \tabfour and \mytabs* uses \tabfive. A good reference for this is Defining starred versions of commands (* macro).

However, I would recommend you use the inline list feature from the enumitem package:

enter image description here

\documentclass{article}
\usepackage[inline]{enumitem}
\begin{document}
\begin{enumerate*}[label=\alph*), itemjoin={\hspace*{5.0ex}}]
  \item 10
  \item 12
  \item 15
\end{enumerate*}

\begin{enumerate*}[label=\alph*), itemjoin={\hspace*{5.0ex}}]
  \item 10
  \item 12
  \item 15
  \item 18
  \item 20
\end{enumerate*}
\end{document}

If you want to keep with your syntax, then something like

\newcounter{answers}
\renewcommand\theanswers{\alph{answers}}
\def\tabendi{\tabend}
\def\tabgen#1\\ \tabend{\setcounter{answers}{0}\noindent\tabgeni#1& & \tabend& }
\def\tabgeni#1& {%
  \def\tempa{#1}%
  \ifx\tempa\tabendi
    \tabend
  \else
    \if\relax\detokenize{#1}\relax
    \else
      \makebox[.18\linewidth][l]{\stepcounter{answers}\theanswers)~#1}\hfill
    \fi
  \expandafter\tabgeni
  \fi
}
\def\tabend{\par}
\let\tabfour\tabgen
\let\tabfive\tabgen

and

\tabgen
    10 &
    12 &
    15 &
    20\\
\tabend

\tabgen
    10 &
    12 &
    15 &
    18 &
    20\\
\tabend

The old syntax would continue to work because of the to \let statements.

However, a different approach might be handier and more liberal for input:

\usepackage{xparse}

\newcounter{answers}
\renewcommand\theanswers{\alph{answers}}
\ExplSyntaxOn
\NewDocumentCommand{\results}{m}
 {
  \seq_set_split:Nnn \l_results_a_seq {,}{#1}
  \par\nobreak\noindent\setcounter{answers}{0}
  \seq_map_inline:Nn \l_results_a_seq
   {
    \makebox[.18\linewidth][l]{\stepcounter{answers}\theanswers)~##1}\hfill
   }
   \par
 }
\seq_new:N \l_results_a_seq
\ExplSyntaxOff

Then you can input your results as

\results{  
  10,  
  12,
  15,
  20
}

\results{
  10,
  12,
  15,
  18,
  20
}

that will produce

enter image description here