# Help if else

**URL:** <https://www.ruby-forum.com/t/help-if-else/110467>\
**Category:** Ruby\
**Created:** [July 26, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/help-if-else/110467 "2007-07-26T16:55:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0nsync](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c4cdca/32.png) [@r0nsync](https://www.ruby-forum.com/u/r0nsync)\
**Post date:** [July 26, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/help-if-else/110467/1 "2007-07-26T16:55:34Z")

</div>

if ((( chaine[i+14] == “twincards\>false\</twincards”)||(chaine[i+14]  
== “twincards\>true\</twincards”))|| ( chaine[i+14]== “twincards  
xsi:nil=“1”/”))

???

: syntax error, expecting end-of-file

???

---

<div class="post-metadata">

**Author:** ![r0nsync](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c4cdca/32.png) [@r0nsync](https://www.ruby-forum.com/u/r0nsync)\
**Post date:** [July 26, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/help-if-else/110467/2 "2007-07-26T17:09:53Z")

</div>

On 7/26/07, Tonyrrr T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if ((( chaine[i+14] == “twincards\>false\</twincards”)||(chaine[i+14]  
> == “twincards\>true\</twincards”))|| ( chaine[i+14]== "twincards

- xsi:nil=“1”/"))

- xsi:nil="1"/"))

you have to escape quotes with \

---

<div class="post-metadata">

**Author:** ![r0nsync](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c4cdca/32.png) [@r0nsync](https://www.ruby-forum.com/u/r0nsync)\
**Post date:** [July 26, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/help-if-else/110467/3 "2007-07-26T17:35:56Z")

</div>

Hi,

Am Freitag, 27. Jul 2007, 00:21:31 +0900 schrieb Ben B.:

> test = chaine[i + 14]  
> if test == ‘twincards\>false\</twincards’ or  
> test == ‘twincards\>true\</twincards’ or  
> test == ‘twincards xsi:nil=“1”/’

It’s not only legibility, it’s enough to calculate c[i+14]  
once as the result is every time the same.

Another suggestion:

case chaine[i+14]  
when %r{twincards\>(true|false)\</twincards},  
%q{twincards xsi:nil=“1”/} then  
…  
end

Bertram

---

<div class="post-metadata">

**Author:** ![r0nsync](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c4cdca/32.png) [@r0nsync](https://www.ruby-forum.com/u/r0nsync)\
**Post date:** [July 26, 2007, 5:23pm UTC](https://www.ruby-forum.com/t/help-if-else/110467/4 "2007-07-26T17:23:55Z")

</div>

On Thu, Jul 26, 2007, Tonyrrr T. wrote:

> if ((( chaine[i+14] == “twincards\>false\</twincards”)||(chaine[i+14]  
> == “twincards\>true\</twincards”))|| ( chaine[i+14]== “twincards  
> xsi:nil=“1”/”))

You’re closing one too many sets of parents after the “true”  
conditional. Also, in the third conditional, you need to either escape  
the inner quotes or use single quotes:

“twincards xsi:nil=“1”/”  
‘twincards xsi:nil=“1”/’

You might want to rewrite it for better legibility, too. A suggestion:

test = chaine[i + 14]  
if test == ‘twincards\>false\</twincards’ or  
test == ‘twincards\>true\</twincards’ or  
test == ‘twincards xsi:nil=“1”/’

```
 # do whatever

```

end

Ben

---

<div class="post-metadata">

**Author:** ![r0nsync](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c4cdca/32.png) [@r0nsync](https://www.ruby-forum.com/u/r0nsync)\
**Post date:** [July 26, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/help-if-else/110467/5 "2007-07-26T17:46:57Z")

</div>

On Fri, Jul 27, 2007, Bertram S. wrote:

> It’s not only legibility, it’s enough to calculate c[i+14]  
> once as the result is every time the same.

Right! I forgot to mention that 🙂

> Another suggestion:
> 
> case chaine[i+14]  
> when %r{twincards\>(true|false)\</twincards},  
> %q{twincards xsi:nil=“1”/} then  
> …  
> end

My gut tells me this might be slower, but probably not enough to matter.  
And I always forget about %q, that’s really the best way to quote  
something that has quotes inside it.

Ben
