Remote-processing CAMBASIC Manuel d'utilisateur Page 72

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 208
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 71
Commands - 39
DO/UNTIL
Statements
SYNTAX: DO
.
.
.
UNTIL expression is true
PURPOSE: To execute a conditional loop structure.
REMARK S: The DO/ UNT IL statements cause a list of statements to be executed until a condition is met. You
may exit a DO/UNTIL with the EXIT statement
EXAMPLE: 10 A= - 45
20 DO
30 INC A:PRINT A
50 UNTIL A=0
Nesting DO/UNT IL loops is permitted. Care must be taken in the construct. The following
example illustrates one of the possible pitfalls:
10 DO
20 DO
30 INC X
40 UNTIL X=5
50 INC Y
60 UNTIL Y=5
In the “inside” loop beginning at line 20, variable X is incremented until X = 5. Line 50 is then
executed. Since Y is now 1, execution branches to line 20. T he prev ious value of X was 5, and it is
now incremented to 6. Since this is greater than 5, the inside loop continues until X overflows (a
very long time).
One solution is to add line 45 to reset X each time so the program will run properly:
45 X=0
ERROR: < UNTIL> if UNTIL encountered without corresponding DO.
Vue de la page 71
1 2 ... 67 68 69 70 71 72 73 74 75 76 77 ... 207 208

Commentaires sur ces manuels

Pas de commentaire