---
title: Keep any value in range
description: "[SPIN](https://obex.parallax.com/code-language/spin/), [SPIN2](https://obex.parallax.com/code-language/spin2/) ## Introduction The Propeller native SPIN and SPIN2 languages include many efficient instructions to solve common programming tasks. For example, how to keep a value between a certain range of allowed values? Here's an example using just one…"
url: "https://obex.parallax.com/docs/chips-tips/propeller-1/keep-any-value-in-range/"
updated: "2024-12-16"
category: Propeller 1
---

# Keep any value in range

[SPIN](https://obex.parallax.com/code-language/spin/), [SPIN2](https://obex.parallax.com/code-language/spin2/)

## Introduction

The Propeller native SPIN and SPIN2 languages include many efficient instructions to solve common programming tasks.

For example, how to keep a value between a certain range of allowed values?

Here's an example using just one line of code!

## Code Snippet

```spin2
value := 1 #> value <# 4               ' Limit value range from 1 to 4
```

The result of the operation follows these rules:

- If value is less than 1, then value = 1
- If value is greater than 4, then value = 4
- If value is 1, 2, 3 or 4, then value will remain unchanged.

---

## Resources

[Parallax Propeller 1 - Spin Language Documentation](https://www.parallax.com/package/propeller-manual)

[Parallax Propeller 2 - Spin2 Language Documentation](https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/preview)

---
