# Check value before returning

**URL:** https://forum.kirupa.com/t/check-value-before-returning/331718
**Category:** flash
**Created:** [October 3, 2013, 5:14pm UTC](https://forum.kirupa.com/t/check-value-before-returning/331718 "2013-10-03T17:14:06Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bonassus](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bonassus](https://forum.kirupa.com/u/bonassus)
#### Post date: [October 3, 2013, 5:14pm UTC](https://forum.kirupa.com/t/check-value-before-returning/331718/1 "2013-10-03T17:14:06Z")

</div>

I’m confused and hoping someone can point me in the right directions.  
I have a class myClass with a getRandomLetter function that returns a String.  
It uses \_model.lettersArray[rp.getNum()]; to get a random letter from an array. the function checks if this new letter is the same value as an unchanging value corLetter. if this value is the same i want a new random letter to be generated and returned. But then i need to check that new letter. but i can’t think of how to do it without causing a recursive loop. Please see code below

l

```auto
etter1:String = myClass.getRandomLetter();

public function getRandomLetter(): String
        {
            newLetter = _model.lettersArray[rp.getNum()];
            var corLetter:String = _model._correctLetter.toLowerCase();

            if(newLetter.toLowerCase() == corLetter)
            {
            newLetter = _model.lettersArray[rp.getNum()];
            }

            return newLetter;
        }

```

thanks in advance for any help
