# Boolean Values That Use && || &&

**URL:** <https://forum.kirupa.com/t/boolean-values-that-use/8529>\
**Category:** flash\
**Created:** [November 22, 2002, 11:55pm UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529 "2002-11-22T23:55:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![waffe](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@waffe](https://forum.kirupa.com/u/waffe)\
**Post date:** [November 22, 2002, 11:55pm UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/1 "2002-11-22T23:55:14Z")

</div>

I am trying to set up if function like this.

my current song position \>=1 and my current song position \<2  
play song 2

You write it like this

if (song.position \>=1 && song.position \<=2){  
gotoandplay(100)

I would like to add another set of paramiters

my current song position \>=3 and my current song position \<4  
play song 2

I have tried to write it like this

if (song.position \>=1 && song.position \<=2 || song.position \>=3 && song.position \<4 ){  
gotoandplay(100)

The code above does not work. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 23, 2002, 12:41am UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/2 "2002-11-23T00:41:33Z")

</div>

Did you try using “or” instead of “||”

If it doesn’t work, don’t mind me, I don’t know what I am talking about. ::slinks into corner::

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 23, 2002, 2:11am UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/3 "2002-11-23T02:11:28Z")

</div>

try using brackets so that your order of operations in the if statement is explicit. flash evaluates && before ||.

trace(false && false || true);  
// traces true

trace(false && (false || true));  
// traces false

your current if statement in english reads:  
if song.position equals 1 or 2 or 3 go to and play 10.

is that what you mean?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 23, 2002, 3:07am UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/4 "2002-11-23T03:07:31Z")

</div>

Beta, I’ll try the or, but I don’t think it will work:rambo:

sbeener, Yes that is excactly what I want my if statement to say.  
I am really trying to put an audio loop over another audio loop in time by rolling over a button and having the second loop start on beat 1,2,3 or 4 of the main loop.

What do you want me to do with the trace command?

What about the else if command to put the multible staments?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 23, 2002, 3:28am UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/5 "2002-11-23T03:28:35Z")

</div>

Just use different if statments instead of the ||, works great.

Thanks people:)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 23, 2002, 9:21pm UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/6 "2002-11-23T21:21:53Z")

</div>

waffe, the traces were meant to illustrate how order of evaluation will change the results.

if that was what you wanted why not say:

sp = song.position;  
if(sp \> 0 && sp \< 4) gotoAndPlay(10);

but if you have it working now probably best not to change it. ; )

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 24, 2002, 7:46am UTC](https://forum.kirupa.com/t/boolean-values-that-use/8529/7 "2002-11-24T07:46:39Z")

</div>

Nice idea but lets say that “sp = 1” is the first beat of the song and “sp = 2” is the second beat of the song and so forth.

Lets say then when I click a button a new sound starts that fits in very well with the ongoing song when it starts on beat 1,2,3 or 4.

There for if I used  
button\_btn.onpress = function(){  
if(sp \> 0 && sp \< 4){  
sound2.play()  
}  
}

The new loop could start any time after I click the button except after beat 4. Most likely this would not sound right because the new loop did not start on beat 1,2,3 or 4.

Thus, I need more resolution in my “if statements” to dictate when my new sound can play.

New problem on this topic, if you would please look at thread “refresh rate = frames or ?”
