Post Reply 
REPEAT . . . UNTIL loop problem
02-13-2021, 10:50 PM (This post was last modified: 02-13-2021 10:51 PM by cahlucas.)
Post: #1
REPEAT . . . UNTIL loop problem
Hi all,
This time I have a loop problem that I cannot solve. For a graphics program, I have a REPEAT - UNTIL loop as the outermost program loop to keep the program running until it ends, see the code below. Somewhere in the code, the value 1 is stored in the variable 'exit' when a certain key is pressed. I get a 'syntax error' when I press the menu key 'Cntrl.', whereby the cursor is just in front of the UNTIL. As far as I can tell there is nothing wrong with the code, but I don't understand where that error message is coming from. Maybe someone can give me an idea to solve this problem. I hope to hear from you soon. Sincerely, Karel.

Code:

 . . .
 LOCAL exit;
 . . .
 exit:=0;
 . . . 
 REPEAT
 . . .
 . . . exit:=1;
 . . . 
 FREEZE;
 UNTIL exit==1;
 . . .

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-13-2021, 11:30 PM
Post: #2
RE: REPEAT . . . UNTIL loop problem
I don't know why you have this syntax error, but I would try two things:
First replace: UNTIL exit==1; by: UNTIL exit;
Then if you (likely) still have the same error, replace:
REPEAT
. . .
UNTIL exit==1;
by:
WHILE exit==0 DO
. . .
END;
Find all posts by this user
Quote this message in a reply
02-13-2021, 11:32 PM (This post was last modified: 02-13-2021 11:33 PM by StephenG1CMZ.)
Post: #3
RE: REPEAT . . . UNTIL loop problem
One possibility when the code looks OK and the variable name is a common name like "exit" - Is it possible that "exit" is a reserved word or used elsewhere?
In such cases you could try a less common name like "ext17" and hope the problem goes away...
Hope the Prime experts can suggest something more helpful.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
02-14-2021, 12:23 AM
Post: #4
RE: REPEAT . . . UNTIL loop problem
(02-13-2021 11:32 PM)StephenG1CMZ Wrote:  One possibility when the code looks OK and the variable name is a common name like "exit" - Is it possible that "exit" is a reserved word or used elsewhere?
In such cases you could try a less common name like "ext17" and hope the problem goes away...
Hope the Prime experts can suggest something more helpful.

Dear Mr. Stephen,
This is tested by me, and it does not work. Still thanks for your answer. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-14-2021, 12:38 AM
Post: #5
RE: REPEAT . . . UNTIL loop problem
(02-13-2021 11:30 PM)Didier Lachieze Wrote:  I don't know why you have this syntax error, but I would try two things:
First replace: UNTIL exit==1; by: UNTIL exit;
Then if you (likely) still have the same error, replace:
REPEAT
. . .
UNTIL exit==1;
by:
WHILE exit==0 DO
. . .
END;

Dear Mr. Lachieze,
Thank you for your answer. The "UNTIL exit" came for the "UNTIL exit == 1;", and it didn't work either. The "WHILE DO END;" loop I have tested, and unfortunately does not work either. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-14-2021, 01:24 AM (This post was last modified: 02-14-2021 03:27 AM by toml_12953.)
Post: #6
RE: REPEAT . . . UNTIL loop problem
(02-13-2021 10:50 PM)cahlucas Wrote:  Hi all,
This time I have a loop problem that I cannot solve. For a graphics program, I have a REPEAT - UNTIL loop as the outermost program loop to keep the program running until it ends, see the code below. Somewhere in the code, the value 1 is stored in the variable 'exit' when a certain key is pressed. I get a 'syntax error' when I press the menu key 'Cntrl.', whereby the cursor is just in front of the UNTIL. As far as I can tell there is nothing wrong with the code, but I don't understand where that error message is coming from. Maybe someone can give me an idea to solve this problem. I hope to hear from you soon. Sincerely, Karel.
This works for me. Are you sure you have exit:=1 in a proper conditional?

Code:

EXPORT TESTEX()
BEGIN

LOCAL y:=0,exit:=0;

REPEAT
  print(y);
  y:=y+1;
  IF y==7 THEN
    exit:=1;
  END;  // If you leave this out, you'll get an error on the UNTIL statement.
UNTIL exit==1;

END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
02-14-2021, 12:16 PM
Post: #7
RE: REPEAT . . . UNTIL loop problem
(02-13-2021 10:50 PM)cahlucas Wrote:  I get a 'syntax error' when I press the menu key 'Cntrl.', whereby the cursor is just in front of the UNTIL ...

Code:
 REPEAT
 . . .
 . . . exit:=1;
 . . . 
 FREEZE;
 UNTIL exit==1;
 . . .

Possibly syntax error is not from loop, but FREEZE ? (or, whatever before it ?)

Just curious, which key is the menu key 'Cntrl' ?
Find all posts by this user
Quote this message in a reply
02-14-2021, 07:46 PM
Post: #8
RE: REPEAT . . . UNTIL loop problem
(02-14-2021 01:24 AM)toml_12953 Wrote:  This works for me. Are you sure you have exit:=1 in a proper conditional?

Code:

EXPORT TESTEX()
BEGIN

LOCAL y:=0,exit:=0;

REPEAT
  print(y);
  y:=y+1;
  IF y==7 THEN
    exit:=1;
  END;  // If you leave this out, you'll get an error on the UNTIL statement.
UNTIL exit==1;

END;

Dear Tom L.,
Yes, I have the command 'exit:=1;' placed in a correct conditional. The error this thread is about has only recently occurred, before that, the program worked fine. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-14-2021, 07:51 PM
Post: #9
RE: REPEAT . . . UNTIL loop problem
I think toml_12953 got it right with a missing END in an IF statement or something similar. The IF statement with a missing END can be located anywhere in the repeat until block.

PHP Code:
EXPORT Test_Until_1()
BEGIN
  LOCAL y
:=0,exit:=0
  PRINT();
  
REPEAT
    
IF y==3 THEN  // if statement unrelated to the loop exit.
      
y:=y;
    
//END;  // If you leave this out, you'll get an error on the UNTIL statement.
    
PRINT(y);
    
y:=y+1;
    IF 
y==7 THEN  // loop exit
      
exit:=1;
    
END
  
UNTIL exit==1;
END
Find all posts by this user
Quote this message in a reply
02-14-2021, 07:58 PM
Post: #10
RE: REPEAT . . . UNTIL loop problem
(02-14-2021 12:16 PM)Albert Chan Wrote:  Possibly syntax error is not from loop, but FREEZE ? (or, whatever before it ?)

Just curious, which key is the menu key 'Cntrl' ?

Dear Mr. Chan,
The syntax error is not caused by a statement before the UNTIL. All the code there is correct. The 'Cntrl.' (or 'Ctrl.') key is the key where you can check the program for syntax errors. You will find it at the bottom right of the other menu keys, if you have a program open for editing. Maybe ever used it? Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-14-2021, 08:09 PM
Post: #11
RE: REPEAT . . . UNTIL loop problem
(02-14-2021 07:51 PM)Gene222 Wrote:  I think toml_12953 got it right with a missing END in an IF statement or something similar. The IF statement with a missing END can be located anywhere in the repeat until block.

PHP Code:
EXPORT Test_Until_1()
BEGIN
  LOCAL y
:=0,exit:=0
  PRINT();
  
REPEAT
    
IF y==3 THEN  // if statement unrelated to the loop exit.
      
y:=y;
    
//END;  // If you leave this out, you'll get an error on the UNTIL statement.
    
PRINT(y);
    
y:=y+1;
    IF 
y==7 THEN  // loop exit
      
exit:=1;
    
END
  
UNTIL exit==1;
END

Dear Mr. Gene,
There is no 'END;' statement forgotten. The 'IF-THEN-END' structure is part of a 'CASE' structure that has been carefully constructed, using the menu from 'Tmplt', in the program editor. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-15-2021, 01:40 AM
Post: #12
RE: REPEAT . . . UNTIL loop problem
(02-14-2021 08:09 PM)cahlucas Wrote:  
(02-14-2021 07:51 PM)Gene222 Wrote:  I think toml_12953 got it right with a missing END in an IF statement or something similar. The IF statement with a missing END can be located anywhere in the repeat until block.

PHP Code:
EXPORT Test_Until_1()
BEGIN
  LOCAL y
:=0,exit:=0
  PRINT();
  
REPEAT
    
IF y==3 THEN  // if statement unrelated to the loop exit.
      
y:=y;
    
//END;  // If you leave this out, you'll get an error on the UNTIL statement.
    
PRINT(y);
    
y:=y+1;
    IF 
y==7 THEN  // loop exit
      
exit:=1;
    
END
  
UNTIL exit==1;
END

Dear Mr. Gene,
There is no 'END;' statement forgotten. The 'IF-THEN-END' structure is part of a 'CASE' structure that has been carefully constructed, using the menu from 'Tmplt', in the program editor. Sincerely, Karel.

If you post the entire program we won't have to guess.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
02-15-2021, 11:27 AM
Post: #13
RE: REPEAT . . . UNTIL loop problem
(02-15-2021 01:40 AM)toml_12953 Wrote:  
(02-14-2021 08:09 PM)cahlucas Wrote:  Dear Mr. Gene,
There is no 'END;' statement forgotten. The 'IF-THEN-END' structure is part of a 'CASE' structure that has been carefully constructed, using the menu from 'Tmplt', in the program editor. Sincerely, Karel.

If you post the entire program we won't have to guess.

REPEAT commands UNTIL test
Executes commands UNTIL test is true

IF..THEN..END...ELSE is not a command.


FOR .... FROM...DO commands

CASE
IF....
IF
END

END

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
02-15-2021, 01:02 PM
Post: #14
RE: REPEAT . . . UNTIL loop problem
(02-15-2021 11:27 AM)Wolfgang Wrote:  
(02-15-2021 01:40 AM)toml_12953 Wrote:  If you post the entire program we won't have to guess.

REPEAT commands UNTIL test
Executes commands UNTIL test is true

IF..THEN..END...ELSE is not a command.


FOR .... FROM...DO commands

CASE
IF....
IF
END

END

That much we know. Obviously, he's either leaving something out of or adding something to his actual program that's causing the problem, though. We'd need to see a copy of the whole program to help him.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
02-15-2021, 01:25 PM
Post: #15
RE: REPEAT . . . UNTIL loop problem
(02-15-2021 01:02 PM)toml_12953 Wrote:  
(02-15-2021 11:27 AM)Wolfgang Wrote:  REPEAT commands UNTIL test
Executes commands UNTIL test is true

IF..THEN..END...ELSE is not a command.


FOR .... FROM...DO commands

CASE
IF....
IF
END

END

That much we know. Obviously, he's either leaving something out of or adding something to his actual program that's causing the problem, though. We'd need to see a copy of the whole program to help him.

i repeat:
The problem are further nested IF Conditions inside a REPEAT... UNTIL LOOP. This is imho not allowed. Hence syntax errors.

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
02-15-2021, 02:43 PM (This post was last modified: 02-15-2021 02:46 PM by Didier Lachieze.)
Post: #16
RE: REPEAT . . . UNTIL loop problem
(02-15-2021 01:25 PM)Wolfgang Wrote:  The problem are further nested IF Conditions inside a REPEAT... UNTIL LOOP. This is imho not allowed. Hence syntax errors.

Well, the program example from the on-calc help for CASE does just that: it includes a CASE statement with several IF THEN END; inside a REPEAT UNTIL loop and there is no syntax error when you press the "Check" soft key (labelled "Cntrl." if you select Nederlands as the calc language). I also tried to add a nested IF THEN ELSE END; inside one of the IF statements and still no syntax error.

If there is a syntax error with the cursor just in front of the UNTIL it means that the UNTIL was not expected at this place, so likely a previous statement is still open hence the missing END; suggestion but, as toml_12953 said, without the original code there is not much more that we can do to help.
Find all posts by this user
Quote this message in a reply
02-15-2021, 03:18 PM (This post was last modified: 02-15-2021 03:24 PM by Wolfgang.)
Post: #17
RE: REPEAT . . . UNTIL loop problem
(02-15-2021 02:43 PM)Didier Lachieze Wrote:  [quote='Wolfgang' pid='143019' dateline='1613395513']


Now, thats an example for CASE.....and not for REPEAT--UNTIL Loops only. The IF Conditions are inside the CASE LOOP

In our example i commented with "// "the lines concerning if condition queries // and there was no syntax check error. a syntax check error ist not urgend pointing to the cause.

I will try it out.

There are a lot workarounds and possibilities for not using repeat..until loops.

https://www.tutorialspoint.com/pascal/pa...l_loop.htm


Attached File(s) Thumbnail(s)
   

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
02-15-2021, 03:26 PM (This post was last modified: 02-15-2021 03:27 PM by Didier Lachieze.)
Post: #18
RE: REPEAT . . . UNTIL loop problem
(02-15-2021 03:18 PM)Wolfgang Wrote:  Now, thats an example for CASE.....and not for REPEAT--UNTIL Loops only. The IF Conditions are inside the CASE LOOP

In this example the CASE loop is included in a REPEAT-UNTIL loop. This is exactly what the OP described for his program:

(02-14-2021 08:09 PM)cahlucas Wrote:  Dear Mr. Gene,
There is no 'END;' statement forgotten. The 'IF-THEN-END' structure is part of a 'CASE' structure that has been carefully constructed, using the menu from 'Tmplt', in the program editor. Sincerely, Karel.

Obviously we need the original program to provide more meaningful answers.
Find all posts by this user
Quote this message in a reply
02-15-2021, 10:20 PM
Post: #19
RE: REPEAT . . . UNTIL loop problem
Make a copy of the program. Then start removing chunks of code from the copy until you discover the cause of the syntax error. The key here is that you don't care of the copy works, you just want to determine the syntax error.
Find all posts by this user
Quote this message in a reply
02-15-2021, 11:03 PM (This post was last modified: 02-15-2021 11:05 PM by cahlucas.)
Post: #20
RE: REPEAT . . . UNTIL loop problem
Here is the framework of my program, at least the part where you can derive control from. I will not publish the entire program here, to keep the overview as simple as possible. Things unrelated to program control have been left out. But this should be enough to track down the error. I hope you can find it. Sincerely, Karel.

Code:


#pragma mode( separator(.,;) integer(h32) )

CURSORTOUCH(n,cx,cy);

START()
BEGIN
 LOCAL N,input,exit,,cx,cy;
 input:=−1;  exit:=0; 
 
 REPEAT
  input:=WAIT(−1);
  CASE
    IF N==0 THEN  END;
    IF TYPE(input)==6 THEN
      CASE
        IF input(1)==#0h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
        IF input(1)==#1h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
        IF input(1)==#2h THEN
        
        END;
        IF input(1)==#3h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
        IF input(1)==#4h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
        IF input(1)==#5h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
        IF input(1)==#6h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
        IF input(1)==#7h THEN
        cx:=B→R(input(2));
        cy:=B→R(input(3));
        END;
      END;
      CURSORTOUCH(N,cx,cy);
    END;
   IF TYPE(input)==0 THEN 
    CASE
     . . .    // More  IF  THEN  END  statements
     IF input==−1 THEN  END;
     IF input==19 THEN exit:=1 END;
     . . .     // More  IF  THEN  END  statements
     IF input==37 THEN N:=4 END;
     IF input==38 THEN N:=5 END;
     IF input==39 THEN N:=6 END;
     . . .     // More  IF  THEN  END  statements
     DEFAULT END;
    END;
  END;
  CASE  // Display section,  This part manages the screen.
    IF N==4 THEN . . . END;
    IF N==5 THEN . . . END;
    IF N==6 THEN . . . END;
  END;
  FREEZE;
 UNTIL exit==1;
 STARTVIEW(−4,1);
END;

CURSORTOUCH(n,cx,cy)
BEGIN
 . . .     // Part where x and y coordinates are processed.
END;


I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)