# Select different rows per loop

**URL:** <https://discourse.psychopy.org/t/select-different-rows-per-loop/31674>\
**Category:** Builder\
**Created:** [November 1, 2022, 11:40pm UTC](https://discourse.psychopy.org/t/select-different-rows-per-loop/31674 "2022-11-01T23:40:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LucindaH](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@LucindaH](https://discourse.psychopy.org/u/LucindaH)\
**Post date:** [November 1, 2022, 11:40pm UTC](https://discourse.psychopy.org/t/select-different-rows-per-loop/31674/1 "2022-11-01T23:40:46Z")

</div>

**What are you trying to achieve?:**  
I am very new to coding. In my experiment, I’m testing memory and there are a study phase, a retention phase and a test phase. There are a total of 3 trials which means all the phases will repeat 3 times. I have 3 sets of 20 math problems (a total of 60 questions, under the file “FillerQ.csv”) created for the retention phase. I want to display each set in random order per trial and receive feedback on each individual answer.

**What did you try to make it work?:**

 ![Screen Shot 2022-11-01 at 7.26.11 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/5/95923acaae16b745ed36a3a40c349bd60a87206b.jpeg)  
I created a loop for the retention task. Within the loop, there is a routine with codes, the math task itself, and a feedback routine. In the code, I put `LoopNum = 0;` under begin experiment and `LoopNum +=1;` under begin routine. In the loop, I put `$((LoopNum-1)*20):(LoopNum*20)` under the selected rows. Running the experiment led to an error as below:

########### Running: /Users/teammaster/Desktop/Experiment\_lastrun.py ###########  
18422.3347 INFO Loaded monitor calibration from [‘2020\_10\_01 16:51’]  
File “/Users/teammaster/Desktop/Experiment\_lastrun.py”, line 603  
trialList=data.importConditions(‘FillerQ.csv’, selection=((LoopNum-1)_20):(LoopNum_20)),  
^  
SyntaxError: invalid syntax  
################ Experiment ended with exit code 1 [pid:34882] #################

I tried (for the selected rows):

- not putting $ in front
- using eval(‘’)  
But nothing worked.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 2, 2022, 9:15pm UTC](https://discourse.psychopy.org/t/select-different-rows-per-loop/31674/2 "2022-11-02T21:15:35Z")

</div>

Try

```auto
$str((LoopNum-1)*20)+':'+str(LoopNum*20)

```

Personally I would put something like

```auto
useRows = str((LoopNum-1)*20)+':'+str(LoopNum*20)

```

in a code component and then put $useRows in the loop
