HP Forums
REPEAT . . . UNTIL loop problem - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: REPEAT . . . UNTIL loop problem (/thread-16314.html)

Pages: 1 2


REPEAT . . . UNTIL loop problem - cahlucas - 02-13-2021 10:50 PM

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;
 . . .



RE: REPEAT . . . UNTIL loop problem - Didier Lachieze - 02-13-2021 11:30 PM

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;


RE: REPEAT . . . UNTIL loop problem - StephenG1CMZ - 02-13-2021 11:32 PM

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.


RE: REPEAT . . . UNTIL loop problem - cahlucas - 02-14-2021 12:23 AM

(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.


RE: REPEAT . . . UNTIL loop problem - cahlucas - 02-14-2021 12:38 AM

(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.


RE: REPEAT . . . UNTIL loop problem - toml_12953 - 02-14-2021 01:24 AM

(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;



RE: REPEAT . . . UNTIL loop problem - Albert Chan - 02-14-2021 12:16 PM

(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' ?


RE: REPEAT . . . UNTIL loop problem - cahlucas - 02-14-2021 07:46 PM

(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.


RE: REPEAT . . . UNTIL loop problem - Gene222 - 02-14-2021 07:51 PM

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



RE: REPEAT . . . UNTIL loop problem - cahlucas - 02-14-2021 07:58 PM

(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.


RE: REPEAT . . . UNTIL loop problem - cahlucas - 02-14-2021 08:09 PM

(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.


RE: REPEAT . . . UNTIL loop problem - toml_12953 - 02-15-2021 01:40 AM

(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.


RE: REPEAT . . . UNTIL loop problem - Wolfgang - 02-15-2021 11:27 AM

(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


RE: REPEAT . . . UNTIL loop problem - toml_12953 - 02-15-2021 01:02 PM

(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.


RE: REPEAT . . . UNTIL loop problem - Wolfgang - 02-15-2021 01:25 PM

(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.


RE: REPEAT . . . UNTIL loop problem - Didier Lachieze - 02-15-2021 02:43 PM

(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.


RE: REPEAT . . . UNTIL loop problem - Wolfgang - 02-15-2021 03:18 PM

(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/pascal_repeat_until_loop.htm



RE: REPEAT . . . UNTIL loop problem - Didier Lachieze - 02-15-2021 03:26 PM

(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.


RE: REPEAT . . . UNTIL loop problem - David Hayden - 02-15-2021 10:20 PM

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.


RE: REPEAT . . . UNTIL loop problem - cahlucas - 02-15-2021 11:03 PM

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;