Author Topic: Problem with "exit for"  (Read 2463 times)

0 Members and 1 Guest are viewing this topic.

Offline pascal111

  • Newbie
  • Posts: 2
    • View Profile
Problem with "exit for"
« on: August 25, 2019, 04:18:45 am »
I'm typing a small program with QB45 and I found a problem when I used "exit for" instead of the direct line number in this part of program:

Workable part without "exit for"
Code: QB64: [Select]
  1. IF x = 1 THEN
  2.         IF NOT (z(UBOUND(z)) = 0) THEN 25
  3.         IF (y MOD 2) <> 0 THEN 20
  4.         FOR i = 1 TO UBOUND(z)
  5.         IF z(i) = y THEN 20
  6.         NEXT i
  7.      IF NOT (z(UBOUND(z)) = 0) THEN 25
  8.      IF (y MOD 2) = 0 THEN 20
  9.      FOR i = 1 TO UBOUND(z)
  10.      IF z(i) = y THEN 20
  11.      NEXT i
  12.      
  13.  
  14.  

same part with "exit for"
Code: QB64: [Select]
  1. IF x = 1 THEN
  2.         IF NOT (z(UBOUND(z)) = 0) THEN 25
  3.         IF (y MOD 2) <> 0 THEN 20
  4.         FOR i = 1 TO UBOUND(z)
  5.         IF z(i) = y THEN EXIT FOR
  6.         NEXT i
  7.         GOTO 20
  8.      IF NOT (z(UBOUND(z)) = 0) THEN 25
  9.      IF (y MOD 2) = 0 THEN 20
  10.      FOR i = 1 TO UBOUND(z)
  11.      IF z(i) = y THEN EXIT FOR
  12.      NEXT i
  13.      GOTO 20
  14.  

the worked program without "exit for":
Code: QB64: [Select]
  1.  
  2. FOR i = 1 TO UBOUND(z)
  3. LET z(i) = 0
  4.  
  5. PRINT "Pick a number in your mind where"
  6. PRINT "n the number is 10 >= n >= 1"
  7. 10 INPUT "Are you ready (y/n)?", s$
  8. IF s$ <> "y" THEN 10
  9.  
  10. INPUT "Est-il pair (o/n)?", s$
  11. IF s$ = "o" THEN x = 1 ELSE LET x = 0
  12.  
  13. 20 LET y = INT((11 - 1) * RND + 1)
  14. IF x = 1 THEN
  15.         IF NOT (z(UBOUND(z)) = 0) THEN 25
  16.         IF (y MOD 2) <> 0 THEN 20
  17.         FOR i = 1 TO UBOUND(z)
  18.         IF z(i) = y THEN 20
  19.         NEXT i
  20.      IF NOT (z(UBOUND(z)) = 0) THEN 25
  21.      IF (y MOD 2) = 0 THEN 20
  22.      FOR i = 1 TO UBOUND(z)
  23.      IF z(i) = y THEN 20
  24.      NEXT i
  25.      
  26.  
  27.  
  28. PRINT "Est-il "; y; " (o/n)";
  29.  
  30. IF s$ = "n" THEN
  31. FOR i = 1 TO UBOUND(z)
  32. IF z(i) = 0 THEN
  33. LET z(i) = y
  34. GOTO 20
  35. GOTO 30
  36.  
  37. PRINT "I told you all possible numbers!!"
  38. 30 END
  39.  

Offline pascal111

  • Newbie
  • Posts: 2
    • View Profile
Re: Problem with "exit for"
« Reply #1 on: August 25, 2019, 06:56:07 am »
I think I discovered the problem, I made an infinite loop without noticing that.