I'm looking for a way to realize a macro with a switch/case control structure (or an array solution), as it exists in every programming language.
MWE:
\documentclass[ngerman,12pt]{article}
\usepackage{etoolbox}
\newcommand*\foo[1]{%
\ifstrequal{#1}{givemea}{box}{}%
\ifstrequal{#1}{drawmea}{circle}{}%
\ifstrequal{#1}{applesidontlikeare}{green}{}%
\ifstrequal{#1}{life}{is full of surprises}{}%
}
\begin{document}
\foo{life}
\end{document}
As you can think of, if I have let's say 500 entries the process will slow down very much, as it compares to every single value in the macro. A \break or \return command would be very useful, so the macro aborts if the value is found.
Addition: My strings also will contain numbers (at every position).
Or are there any packages I can use for the job?
(Since there will be a lot of entries, I consider to split up the one macro into many: \fooa, \foob, ... So, if I invoke \foo{life} it checks the first letter l, and then invokes \fool{life}. That also will speed up the process.)

\csname foo@branch@#1\endcsnamewhere the command\foo@branch@gievemeacontains the code for this value. This will use the internal hash which is really efficient. You can guard this with\ifcsnameand make it more robust with\detokenize. – Stephan Lehmke May 28 '14 at 09:09\expandafter\newcommand\csname foo@branch@abc123(bar);baz\endcsname{expansion text}– Stephan Lehmke May 28 '14 at 09:29\@namedeftrick is certainly the way to go here but depending on the application you have in mind you might also find the packagepgfkeysuseful. Adopting a key-val interface could make your code very readable and flexible, while avoiding reinventing the wheel – Bordaigorl May 28 '14 at 11:13