# \[F--\]"if" statements

**URL:** https://forum.kirupa.com/t/f-if-statements/10259
**Category:** flash
**Created:** [December 28, 2002, 3:09am UTC](https://forum.kirupa.com/t/f-if-statements/10259 "2002-12-28T03:09:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mdipi](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mdipi/32/49_2.png) [@mdipi](https://forum.kirupa.com/u/mdipi)
#### Post date: [December 28, 2002, 3:09am UTC](https://forum.kirupa.com/t/f-if-statements/10259/1 "2002-12-28T03:09:00Z")

</div>

ok here is the deal. in my footer, i would like it so that the ball never goes under 1, but that would be a lot of “if” statements to right it :crazy:. so i was wondering what my options would be. this is the current code:

```auto

if (speed == 0){
speed = 1;
}
if (speed == .01) {
	speed = 1;
}
if (speed == .02) {
	speed = 1;
}
if (speed == .03) {
	speed = 1;
}
if (speed == .04) {
	speed = 1;
}
if (speed == .05) {
	speed = 1;
}
if (speed == .06) {
	speed = 1;
}
if (speed == .07) {
	speed = 1;
}
if (speed == .08) {
	speed = 1;
}
if (speed == .09) {
	speed = 1;
}
if (speed == .1) {
	speed = 1;
}
if (speed == .2) {
	speed = 1;
}
if (speed == .2) {
	speed = 1;
}
if (speed == .3) {
	speed = 1;
}
if (speed == .4) {
	speed = 1;
}
}

```

couldnt i use like:

```auto

if(speed == speed<1){
                speed = 1;
}

```

i will try this, but do you think this will work? if not what can i do?

---

<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: [December 28, 2002, 3:20am UTC](https://forum.kirupa.com/t/f-if-statements/10259/2 "2002-12-28T03:20:13Z")

</div>

> \*Originally posted by [mdipi.com](http://mdipi.com) \*  
> \*\*

```auto

couldnt i use like:

```

if(speed == speed\<1){  
speed = 1;  
}

```auto

i will try this, but do you think this will work? if not what can i do? **

you were close. its just
if(speed&lt;1){
                speed = 1;
}

you can also use

speed = Math.max(speed, 1);
```

---

<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: [December 28, 2002, 3:48am UTC](https://forum.kirupa.com/t/f-if-statements/10259/3 "2002-12-28T03:48:27Z")

</div>

Yes,

```auto
if (speed<1) {
speed = 1;
}

```

Will work…

Math.max??? I think that is something from Flash 4.

Never really used it, To round up you can just do

mySpeed = Math.ceil(speed)

---

<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: [December 28, 2002, 4:02am UTC](https://forum.kirupa.com/t/f-if-statements/10259/4 "2002-12-28T04:02:18Z")

</div>

Math.max is Flash 5 or later. Similarly there is Math.min. You can constrain a variable to a range using these:

variable = Math.min(Math.max(MIN, VARIANT), MAX);

for example if you had a clip you wanted to follow its \_parent.\_xmouse but only between \_xmouse == 100 and \_xmouse == 200 then you can use

this.\_x = Math.min(Math.max(100, \_parent.\_xmouse), 200);

so they’re nice 😉

---

<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: [December 28, 2002, 4:12am UTC](https://forum.kirupa.com/t/f-if-statements/10259/5 "2002-12-28T04:12:49Z")

</div>

Hrm, learn something new everyday…thanks 🙂
