Alkadian Posted September 12, 2023 Share Posted September 12, 2023 (edited) Hi there, I am moving my first steps in this fantastic world of programming the Intellivision. I have been following Oscar's books (well I have started from his first book) and I am bit unclear about the following lines of code for one of his examples in the book (Game Title - As soon as you press a button music starts playing) DO WAIT C=CONT1 LOOP WHILE C DO WAIT C=CONT1 LOOP WHILE C=0 I understand that this has to do with the pressing/releasing of any buttons of the controllers. But I don't fully understand how both loops work. Many thanks in advance for any kind assistance! Edited September 12, 2023 by Alkadian Quote Link to comment Share on other sites More sharing options...
+evg2000 Posted September 12, 2023 Share Posted September 12, 2023 Total guess as I don’t program on intv but looks like first loop basically loops while c is true, so cont1 must be a true value which could be any non negative value possibly, guessing based on second example it defaults to 0. So in one when controller is moved it sets c to a non true value and in second example it sets it to non zero value. Quote Link to comment Share on other sites More sharing options...
Alkadian Posted September 12, 2023 Author Share Posted September 12, 2023 (edited) Thanks! What I don't get is that if I don't press any button CONT1 should be zero and I should be exiting the first loop as c is not true. The way I read the first loop is "wait till any button is pressed, then exit and move to the second loop". I am sure I am missing the obvious here! Edited September 12, 2023 by Alkadian Quote Link to comment Share on other sites More sharing options...
+evg2000 Posted September 12, 2023 Share Posted September 12, 2023 boolean can be true or false but it can also be numeric. zero =true, negative =false. different language use different numeric values. some may use 0 and 1 some may use non negative = true, negative = false. i’ve never seen his book or the intv basic language so i don’t know, but either his book or the basic docs should have it documented. Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted September 12, 2023 Share Posted September 12, 2023 As you may have seen in the book, there are various kinds of loops. The particular kind in your question has very specific characteristics. First, it is a "do" loop, which is typically used when you do not know how many times you need to repeat. Second, it has the "loop condition" at the bottom, which means that it will enter the body of the loop at least once, then test to see if it is done. This is different from testing at the top, which means that it will check to see if the condition for looping is true even before entering the loop for the first time. Third, it uses a "while" test condition, which means that the test must evaluate to true for the loop to repeat. In other words, it will loop while the test evaluates to true, and exit when it is no longer true. Contrast this to the "until" condition which will loop until the test condition evaluates to true, at which point it will stop repeating. One thing to bear in mind is that in IntyBASIC, a test condition is evaluated by comparing it to zero, which is interpreted as false. This means that when the condition expression evaluates to any other value that is not zero, it will be interpreted as true. In short, zero means false; anything else -- absolutely anything else: positive, negative, whatever -- means true. So, with all this at hand, let us see what the loop does: DO WAIT C=CONT1 LOOP WHILE C Because the test condition is at the end, the code inside the loop will be executed at least the first time. It will first wait for the next video frame, then get the current state of the hand-controller into the variable C. It will then test if the value is not-zero. Because it uses "while" it will loop only while the value is true, that is, not zero. In other words, it will loop while the controller is not idle (i.e., not zero). This is typically done to wait for the player to release the controller before accepting a new input. If the controller is idle, the value of C would be zero, and the loop would exit on the very first test, and continue with the program without looping. The second loop, DO WAIT C=CONT1 LOOP WHILE C=0 does a similar thing, except that the test now is to see if C is zero. This means that the loop will iterate while the controller is idle (C is zero, which makes the condition true) and exit when there is an actual value (C is not zero, which makes the condition false). I hope this helps. In the future, may I suggest posting your programming questions in the Programming Forum. There are many people willing to help there, and we don't bite. dZ. 1 1 Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted September 12, 2023 Share Posted September 12, 2023 21 minutes ago, evg2000 said: boolean can be true or false but it can also be numeric. zero =true, negative =false. different language use different numeric values. some may use 0 and 1 some may use non negative = true, negative = false. i’ve never seen his book or the intv basic language so i don’t know, but either his book or the basic docs should have it documented. In IntyBASIC proper true is -1 ($FFFF), and false is zero. However, the -1 value is a compiler convention used as the result of Boolean evaluation, when the output is being assigned to a variable or used as an operand into a larger expression. In reality, any non-zero value is true -- the compiler will generate code to return -1 when so. This is convenient because it makes true the complement of false, so that "NOT true" evaluates to "false," and vice-versa; allowing the use of bitwise operations for logic expressions. dZ. 1 1 Quote Link to comment Share on other sites More sharing options...
Alkadian Posted September 12, 2023 Author Share Posted September 12, 2023 (edited) 20 minutes ago, DZ-Jay said: In IntyBASIC proper true is -1 ($FFFF), and false is zero. However, the -1 value is a compiler convention used as the result of Boolean evaluation, when the output is being assigned to a variable or used as an operand into a larger expression. In reality, any non-zero value is true -- the compiler will generate code to return -1 when so. dZ. Thank you so much for finding the time to respond in such a very detailed way! All clear now, much appreciated! My apologies for posting in the wrong thread! My bad! I will keep it in mind for the future as I know I will have more questions. Thanks again for your comprehensive response! Edited September 12, 2023 by Alkadian 1 Quote Link to comment Share on other sites More sharing options...
Alkadian Posted September 12, 2023 Author Share Posted September 12, 2023 21 minutes ago, evg2000 said: boolean can be true or false but it can also be numeric. zero =true, negative =false. different language use different numeric values. some may use 0 and 1 some may use non negative = true, negative = false. i’ve never seen his book or the intv basic language so i don’t know, but either his book or the basic docs should have it documented. Thanks. Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted September 12, 2023 Share Posted September 12, 2023 1 hour ago, Alkadian said: Thank you so much for finding the time to respond in such a very detailed way! All clear now, much appreciated! My apologies for posting in the wrong thread! My bad! I will keep it in mind for the future as I know I will have more questions. Thanks again for your comprehensive response! No worries, it is my pleasure. I am only paying forward all the help I received in the past from the others. dZ. 1 1 Quote Link to comment Share on other sites More sharing options...
Zendocon Posted September 22, 2023 Share Posted September 22, 2023 On 9/12/2023 at 12:59 PM, Alkadian said: Thank you so much for finding the time to respond in such a very detailed way! All clear now, much appreciated! My apologies for posting in the wrong thread! My bad! I will keep it in mind for the future as I know I will have more questions. Thanks again for your comprehensive response! No worries about posting in the "wrong" thread. We indie devs just spend more time in the development section to help out with questions like this. If you need more help, feel free to reach out. 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.