Opry99er Posted November 15, 2018 Share Posted November 15, 2018 I'm having a brain lapse right now... please assist! This first piece of code fails with a syntax error. The second functions as expected. Thanks! 10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10 10 CALL CLEAR 20 FOR T=110 TO 880 STEP 110 30 IF T=770 THEN S=834 ELSE S=T 40 CALL SOUND(200,220,1,440,1,S,1) 50 NEXT T 60 GOTO 10 Quote Link to comment Share on other sites More sharing options...
+FarmerPotato Posted November 15, 2018 Share Posted November 15, 2018 I'm having a brain lapse right now... please assist! This first piece of code fails with a syntax error. The second functions as expected. Thanks! 10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10 10 CALL CLEAR 20 FOR T=110 TO 880 STEP 110 30 IF T=770 THEN S=834 ELSE S=T 40 CALL SOUND(200,220,1,440,1,S,1) 50 NEXT T 60 GOTO 10 Everything after the ELSE is part of the ELSE statement2. You would need to start a new line after S=T. Or embed the comparison in a formula like this: 10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: S=T-(T=770)*64 :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10 2 Quote Link to comment Share on other sites More sharing options...
Opry99er Posted November 16, 2018 Author Share Posted November 16, 2018 Balls, that's clever. I don't fully get the T=770 within the parenthesis multiplied by 64, but it works. Care to break it down a bit for me? Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted November 16, 2018 Share Posted November 16, 2018 Balls, that's clever. I don't fully get the T=770 within the parenthesis multiplied by 64, but it works. Care to break it down a bit for me? I should give Erik a chance to answer, but (T=770) is a logical relational expression that evaluates to TRUE (-1) or FALSE (0). You can do the rest of the math, I think. [see Erik’s (@FarmerPotato’s) post below.] ...lee Quote Link to comment Share on other sites More sharing options...
Opry99er Posted November 16, 2018 Author Share Posted November 16, 2018 Interesting. Mongo only pawn, in game of life. 1 Quote Link to comment Share on other sites More sharing options...
+FarmerPotato Posted November 16, 2018 Share Posted November 16, 2018 Balls, that's clever. I don't fully get the T=770 within the parenthesis multiplied by 64, but it works. Care to break it down a bit for me? From page 41 of the XB manual RELATIONAL EXPRESSIONS Relational expressions are most often used in the IF-THEN-ELSE statement, but may be used anywhere that numeric expressions are allowed. A relational expression has a value of -1 if it is true and a value of 0 if it is false Evaluate S=T-(T=770)*64 T T=770 *64 T-that === ===== === ===== 660 0 0 660 770 -1 -64 834 880 0 0 880 2 Quote Link to comment Share on other sites More sharing options...
HOME AUTOMATION Posted November 16, 2018 Share Posted November 16, 2018 This is as much as I think I know. (1+1=1)+(1+1=2)=1 or AND logic TRUE (1+1=1)*(1+1=2)=0 or OR logic FALSE I hope I got this right. Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted November 16, 2018 Share Posted November 16, 2018 This is as much as I think I know. (1+1=1)+(1+1=2)=1 or AND logic TRUE (1+1=1)*(1+1=2)=0 or OR logic FALSE I hope I got this right. Backwards. ...lee 1 Quote Link to comment Share on other sites More sharing options...
HOME AUTOMATION Posted November 16, 2018 Share Posted November 16, 2018 I thought you meant backwards so the answer is still right... than I reevaluated! Hence... (1+1=1)+(1+1=2)=1 or OR logic TRUE (1+1=1)*(1+1=2)=0 or AND logic FALSE I took a pill... am I doing any better now. 1 Quote Link to comment Share on other sites More sharing options...
+Lee Stewart Posted November 16, 2018 Share Posted November 16, 2018 I should add that any non-zero value is considered TRUE. A relational expression that is true always evaluates to -1 (all bits on), so if you expanded your example to (1+1=1)+(1+1=2)+(1+2=3) = 0+(-1)+(-1), it would evaluate to -2, which is still considered true even though it does not evaluate to -1—simply because it is not 0. If you want results that evaluate only to -1 when true, you would need to use the logical operators (OR,AND) on the relational expressions instead of the arithmetic operators (+,*). ...lee 1 Quote Link to comment Share on other sites More sharing options...
+TheBF Posted November 16, 2018 Share Posted November 16, 2018 I thought you meant backwards so the answer is still right... than I reevaluated! Hence... (1+1=1)+(1+1=2)=1 or OR logic TRUE (1+1=1)*(1+1=2)=0 or AND logic FALSE I took a pill... am I doing any better now. I'm not very smart so I always like to get the machine's opinion on the matter. :-) Quote Link to comment Share on other sites More sharing options...
HOME AUTOMATION Posted November 16, 2018 Share Posted November 16, 2018 I started to fault your math... but had to hit backspace over and over again... that's pretty good mathing I'm more procedural... expanded expressions... (1+1=1)+(1+1=2)+(1+2=3) = OVERFLOW Months back wrote a 100 line program to calculate the number of steps it took to drive a dot on an 8 x 8 matrix by counting down in reverse (many steps-very slow-unsteady). When my mind was clearer I realized about 10 lines with some multiply instructions would rocket. Quote Link to comment Share on other sites More sharing options...
+TheBF Posted November 16, 2018 Share Posted November 16, 2018 I started to fault your math... but had to hit backspace over and over again... that's pretty good mathing I'm more procedural... expanded expressions... (1+1=1)+(1+1=2)+(1+2=3) = OVERFLOW Months back wrote a 100 line program to calculate the number of steps it took to drive a dot on an 8 x 8 matrix by counting down in reverse (many steps-very slow-unsteady). When my mind was clearer I realized about 10 lines with some multiply instructions would rocket. I took my math from your post, so the credit is all yours. Like I said, I'm not that smart. 1 Quote Link to comment Share on other sites More sharing options...
HOME AUTOMATION Posted November 16, 2018 Share Posted November 16, 2018 Sorry, late post... I got bumped off the net... I was responding to lee... Quote Link to comment Share on other sites More sharing options...
+InsaneMultitasker Posted November 16, 2018 Share Posted November 16, 2018 This first piece of code fails with a syntax error. 10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10 The syntax error is the result of using a IF/THEN conditional with the FOR/NEXT in the same line. This is not allowed* under normal operation. (If you turn off prescan you can get around this restriction; programmer beware. Heatwave uses this trick in a few places; I don't know what the true ramifications are, only that it is doable) 2 Quote Link to comment Share on other sites More sharing options...
RXB Posted November 16, 2018 Share Posted November 16, 2018 The syntax error is the result of using a IF/THEN conditional with the FOR/NEXT in the same line. This is not allowed* under normal operation. (If you turn off prescan you can get around this restriction; programmer beware. Heatwave uses this trick in a few places; I don't know what the true ramifications are, only that it is doable) The result will be a non initialized variable and a crash of XB. Now if the variable in question is already being used like X=11 and later it has FOR X=1 TO 10 it might work. PRESCAN sets up variable names and locations, also Constants and looks for SYNTAX ERRORs or Illegal Line Numbers. Quote Link to comment Share on other sites More sharing options...
+InsaneMultitasker Posted November 16, 2018 Share Posted November 16, 2018 The result will be a non initialized variable and a crash of XB. Now if the variable in question is already being used like X=11 and later it has FOR X=1 TO 10 it might work. PRESCAN sets up variable names and locations, also Constants and looks for SYNTAX ERRORs or Illegal Line Numbers. That might be true to some extent but as I mentioned, turning off prescan allows you to bypass the syntax error/restriction. I just don't know if there are any hidden issues as a result. Not only can you use the if/then with the for/next, you can have an extra NEXT statement under certain conditions. 10 I,X=0 11 !@P- 100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I 110 x=x+1 :: PRINT X :: NEXT I I think Myarc's Advanced BASIC interpreter gets mucked up by doing this sort of thing. I haven't encountered any ill effects with XB version 110. 3 Quote Link to comment Share on other sites More sharing options...
RXB Posted November 17, 2018 Share Posted November 17, 2018 That might be true to some extent but as I mentioned, turning off prescan allows you to bypass the syntax error/restriction. I just don't know if there are any hidden issues as a result. Not only can you use the if/then with the for/next, you can have an extra NEXT statement under certain conditions. 10 I,X=0 11 !@P- 100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I 110 x=x+1 :: PRINT X :: NEXT I I think Myarc's Advanced BASIC interpreter gets mucked up by doing this sort of thing. I haven't encountered any ill effects with XB version 110. As I said PRESCAN looks for and sets up Variables so your example followed exactly what I said thanks. Quote Link to comment Share on other sites More sharing options...
+InsaneMultitasker Posted November 17, 2018 Share Posted November 17, 2018 As I said PRESCAN looks for and sets up Variables so your example followed exactly what I said thanks. I disagree. The FOR/NEXT error has nothing to do with variable scanning and setup. Two separate issues altogether. Quote Link to comment Share on other sites More sharing options...
RXB Posted November 17, 2018 Share Posted November 17, 2018 I disagree. The FOR/NEXT error has nothing to do with variable scanning and setup. Two separate issues altogether. Really just because it says SYNTAX ERROR in 12 even though there is no SYNTAX ERROR. 11 !@P- 12 I,X=0 100 FOR I=1 TO 10 :: IF I=5 then X=X+100 :: PRINT X;"I was 5" :: NEXT I 110 X=X+1 :: PRINT X :: NEXT I So why do you think it says SYNTAX ERROR in LINE 12??? Yet if you delete LINE 11 it finds the real SYNTAX ERROR IN 100? (NEXT AT THE END OF A IF THEN) Now take out the :: NEXT I at end of the IF THEN And magically it now works? HUH? What do you think is going on? 100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I 110 x=x+1 :: PRINT X :: NEXT I Quote Link to comment Share on other sites More sharing options...
HOME AUTOMATION Posted November 17, 2018 Share Posted November 17, 2018 At least for us there's always more to know!!! Others must keep reinventing what they already have... Quote Link to comment Share on other sites More sharing options...
+InsaneMultitasker Posted November 17, 2018 Share Posted November 17, 2018 Really just because it says SYNTAX ERROR in 12 even though there is no SYNTAX ERROR. The point is that in Owen's original post,the syntax error was caused by incorrect placement of the NEXT statement. My example program /as written/ was meant only to share how one could fool XB into executing (and ignoring) the error; it does not generate an error in the assignment line nor does it contain a line 12. Quote Link to comment Share on other sites More sharing options...
RXB Posted November 18, 2018 Share Posted November 18, 2018 (edited) The point is that in Owen's original post,the syntax error was caused by incorrect placement of the NEXT statement. My example program /as written/ was meant only to share how one could fool XB into executing (and ignoring) the error; it does not generate an error in the assignment line nor does it contain a line 12. Very True, and what I said about PRESCAN is also true...which is why you had to bypass it. with !@P- I know the inside of XB code pretty well and it does not do a great job of analyzing exaclty what the problem is so defaults to SYNTAX ERROR Even when that is not the problem. Edited November 18, 2018 by RXB 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.