Search code examples
c#compiler-constructionprogramming-languageslanguage-designlexical-analysis

If you are forced to simplify C# looping keywords, choose only one you want to preserve


If you are forced to simplify C# keywords that can be used for looping, choose only one you want to preserve.

  • for
  • do-while
  • while
  • goto-label-if
  • foreach

Is there any performance consideration regarding your decision?

Actually I don't know the internal mechanism of them, so here I want interview those of you know the details. However, someone already closed it. So sad!


Solution

  • goto-label-if is not actually looping. And you missed foreach.

    CS theory states, that you only need while to express everything else (even conditional statements), so I'll preserve it. If you were to invent truly minimal imperative programming language, subroutine calls and while loop will suffice.