Browse Source

+ Added Break and Continue

michael 26 years ago
parent
commit
8442c247b1
5 changed files with 119 additions and 2 deletions
  1. 56 0
      docs/ref.tex
  2. 1 1
      docs/refex/Makefile
  3. 4 1
      docs/refex/README
  4. 29 0
      docs/refex/ex86.pp
  5. 29 0
      docs/refex/ex87.pp

+ 56 - 0
docs/ref.tex

@@ -2759,6 +2759,11 @@ For I := 100 downto 1 do
 For I := 1 to 7*dwarfs do KissDwarf(i);
 For I := 1 to 7*dwarfs do KissDwarf(i);
 \end{verbatim}
 \end{verbatim}
 
 
+If the statement is a compound statement, then  the \seep{Break} and 
+\seep{Continue} reserved words can be used to jump to the end or just 
+after the end of the \var{For} statement.
+
+
 \subsection{The \var{Repeat..until} statement}
 \subsection{The \var{Repeat..until} statement}
 The \var{repeat} statement is used to execute a statement until a certain
 The \var{repeat} statement is used to execute a statement until a certain
 condition is reached. The statement will be executed at least once.
 condition is reached. The statement will be executed at least once.
@@ -2781,6 +2786,9 @@ repeat
  X := X/2
  X := X/2
 until x<10e-3
 until x<10e-3
 \end{verbatim}
 \end{verbatim}
+The \seep{Break} and \seep{Continue} reserved words can be used to jump to
+the end or just after the end of the \var{repeat .. until } statement.
+
 \subsection{The \var{While..do} statement}
 \subsection{The \var{While..do} statement}
 A \var{while} statement is used to execute a statement as long as a certain
 A \var{while} statement is used to execute a statement as long as a certain
 condition holds. This may imply that the statement is never executed.
 condition holds. This may imply that the statement is never executed.
@@ -2806,6 +2814,11 @@ while x>=10e-3 do
   X := X/2;
   X := X/2;
 \end{verbatim}
 \end{verbatim}
 They correspond to the example loops for the \var{repeat} statements.
 They correspond to the example loops for the \var{repeat} statements.
+
+If the statement is a compound statement, then  the \seep{Break} and 
+\seep{Continue} reserved words can be used to jump to the end or just 
+after the end of the \var{While} statement.
+
 \subsection{The \var{With} statement}
 \subsection{The \var{With} statement}
 \label{se:With}
 \label{se:With}
 The \var{with} statement serves to access the elements of a record\footnote{
 The \var{with} statement serves to access the elements of a record\footnote{
@@ -4109,6 +4122,27 @@ written to disk.
 
 
 For the example, see \seep{Blockread}.
 For the example, see \seep{Blockread}.
 
 
+\begin{procedure}{Break}
+\Declaration
+Procedure Break;
+\Description
+\var{Break} jumps to the statement following the end of the current 
+repetitive statement. The code between the \var{Break} call and 
+the end of the repetitive statement is skipped. 
+The condition of the repetitive statement is NOT evaluated.
+
+This can be used with \var{For}, var{repeat} and \var{While} statements.
+
+Note that while this is a procedure, \var{Break} is a reserved word
+and hence cannot be redefined.
+\Errors
+None.
+\SeeAlso
+\seep{Continue}, \seep{Exit}
+\end{procedure}
+
+\FPCexample{ex87}
+
 \begin{procedure}{Chdir}
 \begin{procedure}{Chdir}
 \Declaration
 \Declaration
 Procedure Chdir (const S : string);
 Procedure Chdir (const S : string);
@@ -4169,6 +4203,28 @@ None.
 
 
 \FPCexample{ex10}
 \FPCexample{ex10}
 
 
+\begin{procedure}{Continue}
+\Declaration
+Procedure Continue;
+\Description
+\var{Continue} jumps to the end of the current repetitive statement. 
+The code between the \var{Continue} call and the end of the repetitive 
+statement is skipped. The condition of the repetitive statement is then
+checked again.
+
+This can be used with \var{For}, var{repeat} and \var{While} statements.
+
+Note that while this is a procedure, \var{Continue} is a reserved word
+and hence cannot be redefined.
+\Errors
+None.
+\SeeAlso
+\seep{Break}, \seep{Exit}
+\end{procedure}
+
+\FPCexample{ex86}
+
+
 \begin{function}{Copy}
 \begin{function}{Copy}
 \Declaration
 \Declaration
 Function Copy (Const S : String;Index : Integer;Count : Byte) : String;
 Function Copy (Const S : String;Index : Integer;Count : Byte) : String;

+ 1 - 1
docs/refex/Makefile

@@ -38,7 +38,7 @@ OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 \
         ex41 ex42 ex43 ex44 ex45 ex46 ex47 ex48 ex49 ex50 ex51 ex52 ex53 \
         ex41 ex42 ex43 ex44 ex45 ex46 ex47 ex48 ex49 ex50 ex51 ex52 ex53 \
         ex54 ex55 ex56 ex57 ex58 ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 \
         ex54 ex55 ex56 ex57 ex58 ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 \
         ex67 ex68 ex69 ex70 ex71 ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 \
         ex67 ex68 ex69 ex70 ex71 ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 \
-	ex80 ex81 ex82 ex83 ex84 ex85
+	ex80 ex81 ex82 ex83 ex84 ex85 ex86 ex87
 
 
 TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
 TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
 
 

+ 4 - 1
docs/refex/README

@@ -86,4 +86,7 @@ ex80.pp contains an example of the High/Low functions.
 ex81.pp contains an example of the HexStr function.
 ex81.pp contains an example of the HexStr function.
 ex82.pp contains an example of the BinStr function.
 ex82.pp contains an example of the BinStr function.
 ex83.pp contains an example of the Assigned function.
 ex83.pp contains an example of the Assigned function.
-ex84.pp contains an example of the Library keyword.ex85.pp contains an example of the SetLength function.
+ex84.pp contains an example of the Library keyword.
+ex85.pp contains an example of the SetLength function.
+ex86.pp contains an example of the Continue function.
+ex87.pp contains an example of the Break function.

+ 29 - 0
docs/refex/ex86.pp

@@ -0,0 +1,29 @@
+Program Example86;
+
+{ Program to demonstrate the Continue function. }
+
+Var I : longint;
+
+begin
+  I:=0;
+  While I<10 Do 
+    begin
+    Inc(I);
+    If I<5 Then 
+      Continue;
+    Writeln (i);
+    end;
+  I:=0;
+  Repeat
+    Inc(I);
+    If I<5 Then 
+      Continue;
+    Writeln (i);
+  Until I>=10;
+  For I:=1 to 10 do
+    begin
+    If I<5 Then 
+      Continue;
+    Writeln (i);
+    end;
+end.

+ 29 - 0
docs/refex/ex87.pp

@@ -0,0 +1,29 @@
+Program Example87;
+
+{ Program to demonstrate the Break function. }
+
+Var I : longint;
+
+begin
+  I:=0;
+  While I<10 Do 
+    begin
+    Inc(I);
+    If I>5 Then 
+      Break;
+    Writeln (i);
+    end;
+  I:=0;
+  Repeat
+    Inc(I);
+    If I>5 Then 
+      Break;
+    Writeln (i);
+  Until I>=10;
+  For I:=1 to 10 do
+    begin
+    If I>5 Then 
+      Break;
+    Writeln (i);
+    end;
+end.