# Can anyone explain why these two loops do different things?

**URL:** <https://in-thread.sonic-pi.net/t/can-anyone-explain-why-these-two-loops-do-different-things/9051>\
**Category:** Support, Help & Resources\
**Created:** [July 17, 2024, 1:09pm UTC](https://in-thread.sonic-pi.net/t/can-anyone-explain-why-these-two-loops-do-different-things/9051 "2024-07-17T13:09:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![halloworld](https://avatars.discourse-cdn.com/v4/letter/h/cdc98d/32.png) [@halloworld](https://in-thread.sonic-pi.net/u/halloworld)\
**Post date:** [July 17, 2024, 1:09pm UTC](https://in-thread.sonic-pi.net/t/can-anyone-explain-why-these-two-loops-do-different-things/9051/1 "2024-07-17T13:09:04Z")

</div>

hello! Just working on sample slicing and saw this loop from the tutorial appendix section:

```ruby
live_loop :samp_slicer do
  n = 8
  s = line(0,1, steps: n).choose
  f = s+ (1.0/n)
  sample :loop_amen, beat_stretch: 2, start: s, finish: f
  sleep 2.0/n
end

```

It works wonderfully of course, but I assumed it would work the same as the following live loop which I use in my songs, but when I compared them they sound different - the first is constantly changing (with some slice repeats), and the second live loop (below) chooses one slice out of the n1 = 8 possible slices and then plays this same slice every iteration. I assumed that it would choose a new slice each loop, why is this not the case?

```ruby
live_loop :samp_slicer2 do
  n1 = 8
  sample :loop_amen, beat_stretch: 2, num_slices: n1, slice: choose
  sleep 2.0/n1
end

```

Warmly,  
Halloworld 😃

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [July 17, 2024, 2:40pm UTC](https://in-thread.sonic-pi.net/t/can-anyone-explain-why-these-two-loops-do-different-things/9051/2 "2024-07-17T14:40:56Z")

</div>

Hi @halloworld  
I’m not getting repeating slices, your 2nd example works as expected - choosing a different slice number each iteration. Even if I change some opts and var names, it works fine. This would suggest there is something elsewhere in your code that is throwing this off.

```ruby
live_loop :samp_slicer2 do
  num = 4
  sample :loop_amen, num_slices: num, slice: choose
  sleep 2.0/num
end

```

PD-Pi

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [July 17, 2024, 2:43pm UTC](https://in-thread.sonic-pi.net/t/can-anyone-explain-why-these-two-loops-do-different-things/9051/3 "2024-07-17T14:43:10Z")

</div>

. . . and here’s the proof:

```ruby
live_loop :proof do
  tick
  num = 8
  sample :loop_amen, beat_stretch: 2, num_slices: num, slice: look
  sleep 2.0/num
end

```

---

<div class="post-metadata">

**Author:** ![halloworld](https://avatars.discourse-cdn.com/v4/letter/h/cdc98d/32.png) [@halloworld](https://in-thread.sonic-pi.net/u/halloworld)\
**Post date:** [July 18, 2024, 8:50am UTC](https://in-thread.sonic-pi.net/t/can-anyone-explain-why-these-two-loops-do-different-things/9051/4 "2024-07-18T08:50:47Z")

</div>

Hey thanks so much!

I restarted Sonic Pi and then behaved as I expected, I appreciate you testing it!
