I'm trying to make a little program and I am having problems with a procedure that loops once for no apparent reason... run the program and see what I mean (select option 3) here's the code, ignore all except the procedure called game...
Basically, when you select 3 in the main menu it is supposed to tell u what the range of colours is and how many, then ask for a user input, then, when you press return, call a function (which i have not coded yet) to check syntax. As you see when u run it, the function is called straight away and the guesscount is upped by one... I'm confused!!!! heeeeeelp!!!!
Damn it's been over 10 years since I looked at Pascal code, so excuse any dust... Your saying that your do .. until() loop is exiting after one pass, and that looks correct given the code. the termination condition is (guess_result = false), and you se guess _result equal to the return value from guess_check(), which in your definition always returns false. So what you describe is exactly what I'd expect, if my Pascal parsing skillz are still okay after lo these many years. If you want the loop to execute more than once, you'll have to arrange for guess_check() to return true occasionally.
repeat write ('Please enter your guess>'); readln (dummy) {test dummy line} readln ( guess ); guess_result := guess_check (guess); until guess_result = false; that's what is giving me the issue... It seems to run twice whenever I call procedure game I have even put a dummy readln there to test my theory and it automatically fills "dummy" with nothing and continues to the next read line. the thing is, next time it loops it calls for "dummy" and "guess".
Don't have time atm to check the code, but I just want to slap your fingers for typing something like "guess_result = false"!! *slap* there, here's the last code rewritten for you: repeat write ('Please enter your guess>'); readln (dummy) {test dummy line} readln ( guess ); guess_result := guess_check (guess); until not guess_result; well, I can't blame ya, I've done it way too many times myself, also something I did lots was "until guess_result = true", which can be replaced by "until guess_result"... (I'll check the code tomorrow, now need sleep )
Like I said it has been a long time--I blink whenver I see "if(foo=bar)" in any form because in C it's a legitimate construct that probably doesn't mean what you think it does. I do know := is assignment in Pascal, but it's a habit thing....