Path: utzoo!attcan!utgpu!watmath!iuvax!uxc.cso.uiuc.edu!dino!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: "arithmetic if":: Re: Feature for the next C version Message-ID: <1287@atanasoff.cs.iastate.edu> Date: 2 Aug 89 14:37:36 GMT References: <55480@tut.cis.ohio-state.edu> <1989Jul20.152935.14872@utzoo.uucp> <67@motto.UUCP> <18764@mimsy.UUCP> <1389@crdgw1.crd.ge.com> <8515@batcomputer.tn.cornell.edu> <1429@crdgw1.crd.ge.com> Reply-To: hascall@atanasoff.cs.iastate.edu.UUCP (John Hascall) Organization: Iowa State Univ. Computation Center Lines: 42 In article <1429@crdgw1.crd.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes: >someone pointed out, I'm not looking for arithmetic IF, but a way to do >three separate things based on a value, usually the compare of two >values in a sort or tree search. > Some interesting ideas: > ifcase > (a < b) code; code; > (a == b) more(code); > (a > b) still(more); > endcase; This reminds my of an exec language I somtimes program in (no, you haven't heard of it), where you use: cases begin case (expression1) statement1 case (expression2) statement2 : : end And it evaluates each expression in order and executes the (possibly compound) statement of the first one (if any) which is true. [and you just use "case (true)" at the end for "default:"]. Of course, neither of these solve the original problem of how to execute a 3-way branch with a single expression evaluation. Imagine extending the concept: if (expr) s1; [else s2;] to: negative (expr) s1; [zero s2;] [positive s3;] I can hear the C-purists screaming in agony :-) John Hascall