Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!hpda!hpihoah!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.lang.c Subject: Re: C test Message-ID: <2550025@hpisod2.HP.COM> Date: Sun, 2-Aug-87 00:16:08 EDT Article-I.D.: hpisod2.2550025 Posted: Sun Aug 2 00:16:08 1987 Date-Received: Tue, 4-Aug-87 00:50:23 EDT References: <1090@gilsys.UUCP> Organization: Hewlett Packard, Cupertino Lines: 40 > Improve the following code fragment through reorganization: > > { > if (A) { B; return; } > if (C) { D; return; } > if (E) { F; return; } > G; return; > } I have several answers to this; each would be the "right" answer depending on who is asking the question and what hidden agenda they have. 1) Since we do not know whether the definitions, if any, of A, B, C, etc., contain imbalanced syntactic tokens, there is no way to change this fragment without possibly breaking the code. 2) { if (A) B; else if (C) D; else if (E) F; else G; return; /* If the braces enclose a complete function definition rather than a nested block, this statement should be deleted. */ } 3) This is for the APL freak; it assumes B, D, F, G are expressions: { A?B : C?D : E?F : G; return; } I suppose my best answer would be 2, and then 1, and then 3 (if I thought the person was probably psychotic). Dave Decot hpda!decot