in reply to Looped around my neck (help with my poor little loops!)

Psedo code
set $max_tries to 3. ask user for $range of guess generate $answer as a random number from 1..$range FOR $loop from 1 to $max_tries $guess_count = $loop get $user_guess if $user_guess is the $answer then exit loop ENDFOR IF $user_guess equals the $answer message : Well done, you got it in $guess_count ELSE message : Sorry, you've had $max_tries guesses ENDIF
poj

Replies are listed 'Best First'.
Re: Re: Looped around my neck (help with my poor little loops!)
by sulfericacid (Deacon) on Mar 15, 2003 at 23:49 UTC
    If the way you wrote it works you definately make me think I wrote the whole thing backwards, in reverse and in some non-textual language, lol. The only thing I don't understand is what you mean by:

    FOR $loop from 1 to $max_tries $guess_count = $loop
    Are you saying I should do a:

    for ( increment # of guesses to $max_tries) { # no clue what the 2nd line means then
    ? Thanks so much for your help, looks like I totally globbed this script up.

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
      I found that when you jump out of the loop with last you lose the value of the $loop variable
      If you need it later like in the message you need to store it with $guess_count=$loop, that's all it does
      poj
        Ok, I'm slow so please forgive me. I've never heard of a loop variable unless you mean any variables contained within the loop itself not being able to be used outside of the loop unless it's a global variable. Or is $loop a built in variable I haven't heard of before? *sigh* If you find the book of all knowledge please feel free to lend it to me, lol.

        Thanks for your help.

        "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

        sulfericacid