## Re: if/else-if blocks in Obj-C

 Re: if/else-if blocks in Obj-C From: Nick Kocharhook - 2003-03-26 03:29:44 ```On Tue, Mar 25, 2003 at 11:03:28AM -0500, Liam mac Lynne proclaimed: > c=1 //for argument's sake > if (c==1) { > //some stuff > } else if (c!=0) { > //different stuff > } My algorithms teacher would have a heart attack if she saw this code. :-) Alan already answered your question, but really there should never be a situation wherein two blocks of an if statement overlap. Perhaps that if block should be re-thought? -- Nick Kocharhook -- -- Rot-13 ```

 if/else-if blocks in Obj-C From: Liam mac Lynne - 2003-03-25 16:04:36 ```If you have a uniquely-valued variable C, and you write an if block such as this: c=1 //for argument's sake if (c==1) { //some stuff } else if (c!=0) { //different stuff } Do both "some stuff" and "different stuff" get executed, a la a similarly-cased switch block w/ no "break" statements? Both if's qualifying statements _are_ valid, so long as part of "some stuff" doesn't include changing the value of c to zero. Thanks! Liam "If we keep our pride Though Paradise is lost We will pay the price But we will not count the cost" -Rush, 'Bravado', _Roll_the_Bones_ ```
 Re: if/else-if blocks in Obj-C From: Alan Humpherys - 2003-03-25 16:24:04 ```By definition, only one block of an if-else statement will be executed (this holds true for C, C++, Java, & ObjectiveC) If you truly want both blocks to have the potential of being executed, put them into two separate "if" blocks as follows: if (c==1) { //some stuff } if (c!=0) { //different stuff } Alan On Tuesday, March 25, 2003, at 09:03 AM, Liam mac Lynne wrote: > If you have a uniquely-valued variable C, and you write an if block > such > as this: > > c=1 //for argument's sake > if (c==1) { > //some stuff > } else if (c!=0) { > //different stuff > } > > Do both "some stuff" and "different stuff" get executed, a la a > similarly-cased switch block w/ no "break" statements? Both if's > qualifying statements _are_ valid, so long as part of "some stuff" > doesn't > include changing the value of c to zero. > Thanks! > Liam > > "If we keep our pride > Though Paradise is lost > We will pay the price > But we will not count the cost" > -Rush, 'Bravado', _Roll_the_Bones_ > > > > ------------------------------------------------------- > This SF.net email is sponsored by: > The Definitive IT and Networking Event. Be There! > NetWorld+Interop Las Vegas 2003 -- Register today! > http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en > _______________________________________________ > fire-development mailing list > fire-development@... > https://lists.sourceforge.net/lists/listinfo/fire-development ```
 Re: if/else-if blocks in Obj-C From: Liam mac Lynne - 2003-03-25 16:32:47 ```On Tue, 25 Mar 2003, Alan Humpherys wrote: > By definition, only one block of an if-else statement will be executed > (this holds true for C, C++, Java, & ObjectiveC) Oh, good. That means that the if-block in receiveKey that's been bothering me doesn't doubly execute a [msg release] . It has exactly the kind of condition choices I outlined in my first email. *sigh* I wish I'd had time last night to pick at this & learn the involved code (at least!) a little better. Usually, I write or see conditions in if-blocks etc. that are mutually exclusive, and so the point I was asking about isn't relevant, and therefore something that easily slips my mind. Thanks again. Slan, Liam "If we keep our pride Though Paradise is lost We will pay the price But we will not count the cost" -Rush, 'Bravado', _Roll_the_Bones_ ```
 Re: if/else-if blocks in Obj-C From: Nick Kocharhook - 2003-03-26 03:29:44 ```On Tue, Mar 25, 2003 at 11:03:28AM -0500, Liam mac Lynne proclaimed: > c=1 //for argument's sake > if (c==1) { > //some stuff > } else if (c!=0) { > //different stuff > } My algorithms teacher would have a heart attack if she saw this code. :-) Alan already answered your question, but really there should never be a situation wherein two blocks of an if statement overlap. Perhaps that if block should be re-thought? -- Nick Kocharhook -- -- Rot-13 ```