Replacing a switch

From: Paul F. Johnson (paul_at_all-the-johnsons.co.uk)
Date: 01/15/04


Date: Wed, 14 Jan 2004 23:01:33 +0000

Hi,

I'm trying to re-write this piece of code. I've seen it done another way
which was much nicer (to my mind)

The code is

string t;
switch (Einhaft)
{
  case 0:
      t = " pt";
      break;
  case 1:
      t = " mm";
      break;
  case 2 :
      t = " pica";
      break;
}

Now, I'm trying to change this to be something like

t = ((" pt" && Einhaft == 0) || (" mm" && Einhaft == 1) ||
     (" pica" && Einhaft == 2));

A quick test and this will compile, but t doesn't contain what I would
have thought it would contain.

Any ideas what I'm doing wrong?

TTFN

Paul



Relevant Pages

  • Re: switch statement - ANSI-C
    ... Keep in mind, the OP in question here was originally asking about how ... to do a switch on string arguments. ... Someone that unfamiliar with the ...
    (comp.lang.c)
  • Re: Change Text to Memo
    ... Switch a given table field to Memo ... Function SwitchFieldType(sDb As String, sTableName As String, sFieldName ... Dim sSQL As String ... If Err.Number = 0 Then Exit Function ...
    (microsoft.public.access.modulesdaovba)
  • Re: proposal: reswitch
    ... > which levels of loops and/or switches and/or ... socket -server command ?-myaddr addr? ... You've got the quick-exit (break, no string), the fall-through to next ... -switch option), then it'd be the nth switch. ...
    (comp.lang.tcl)
  • Re: Large text file import: MVP question
    ... Simple solutions give fast processing ... One thing you have to keep in mind. ... througput time than from the basic Net namespace. ... change, with mid, split, tolower, or whatever will result in a new string. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: String-based Switch Request...
    ... Facilitate good callback programming design and modularization within GUI code ... When ever switch statements are used, they are typically over used being favour over polymorphism, which leads to brittle shoddy design. ... Use the string type-code as the Key and a Command or Strategy Object as the Value. ...
    (comp.lang.java.programmer)