# Conditionally skip code routine based on block

**URL:** https://discourse.psychopy.org/t/conditionally-skip-code-routine-based-on-block/31108
**Category:** Coding
**Created:** [September 26, 2022, 10:44pm UTC](https://discourse.psychopy.org/t/conditionally-skip-code-routine-based-on-block/31108 "2022-09-26T22:44:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cjb10](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@cjb10](https://discourse.psychopy.org/u/cjb10)
#### Post date: [September 26, 2022, 10:44pm UTC](https://discourse.psychopy.org/t/conditionally-skip-code-routine-based-on-block/31108/1 "2022-09-26T22:44:48Z")

</div>

I have two routines that each contain their own code component:

![Screen Shot 2022-09-26 at 5.35.35 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/3/13cb210301ef867ab1b8ef282af92da4b6006f9e.png)

During my welcome screen, I create a variable ‘Block’ which is determined by generating a random number:

![Screen Shot 2022-09-26 at 5.34.38 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/1/51efeb2ca81d43de732c7b7df56a6d5039c16197.png)

What I am trying to do is only run one of the code routines (‘negCode’ or ‘posCode’) conditionally based on which group is assigned at the beginning of the experiment:

I’ve tried using ‘continueRoutine = False’ to conditionally run one of the two, in both Begin Routine and Each Frame, but that doesn’t do anything.

Hoping someone has a suggestion for a possible solution. Please let me know if you need more information.

---

<div class="post-metadata">

### Author: ![ajus](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@ajus](https://discourse.psychopy.org/u/ajus)
#### Post date: [September 27, 2022, 7:20am UTC](https://discourse.psychopy.org/t/conditionally-skip-code-routine-based-on-block/31108/2 "2022-09-27T07:20:09Z")

</div>

Is it important to you experiment that both of these code components are in their own routine? If not, you could simply copy-paste the code of these components into the if-statement itself.

Otherwise you could preface both code components in their separate routines with an if-statement.

---

<div class="post-metadata">

### Author: ![cjb10](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@cjb10](https://discourse.psychopy.org/u/cjb10)
#### Post date: [September 27, 2022, 2:30pm UTC](https://discourse.psychopy.org/t/conditionally-skip-code-routine-based-on-block/31108/3 "2022-09-27T14:30:50Z")

</div>

That worked perfectly, thank you!
