Path: utzoo!attcan!uunet!yale!mfci!karzes From: karzes@mfci.UUCP (Tom Karzes) Newsgroups: comp.lang.c Subject: Re: Problem with ()?():() as ending test in for-loop Message-ID: <877@m3.mfci.UUCP> Date: 26 May 89 19:16:30 GMT References: <1200@liszt.kulesat.uucp> <17722@mimsy.UUCP> <779@attila.WEITEK.COM> Sender: karzes@mfci.UUCP Reply-To: karzes@mfci.UUCP (Tom Karzes) Organization: Multiflow Computer Inc., Branford Ct. 06405 Lines: 14 In article <779@attila.WEITEK.COM> kens@attila.WEITEK.COM (Ken Stanley) writes: }The specific example: "((n % 10) != 0 && k > 2) || n < 100" works because }when n = 100, (n % 10) == 0 and ! (n < 100). However, if the loop increment }were 3 instead of 1, it would not. }... }... these two statements are identical: } }for (n = 1; ((n % 10) != 0 && k > 2) || n < 100; n++) }for (n = 1; ((n % 10) ? (k > 2) : (n < 100); n++) No, these two statements are not identical, even in this context. Consider the case where n is 11 and k is 1. The original ?: expression evaluates to 0, whereas the incorrect alternate form evaluates to 1. (By the way, the second expression shown above has unbalanced parentheses.)