Wednesday, 19 May 2010

Break and Continue Statement ( Delphi Tutorial # 14 )

Break

Break is a procedure to jump out or quit the looping statement (if, repeat or while). Break is usually called in an if statement.

Example :

program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;

var
  number, stop : integer;
begin
  write('Conter will be stopped at : ');
  readln(stop);
  for number := 1 to 1000 do
    begin
      if number = stop +1 then break;
      writeln(number);
    end;
  readln;
end.

Continue

Continue is a procedure that is used for skipping to next iteration in a looping statement (if, repeat or while). It is also called in an if statement.

Example 1 (writing odd numbers from 1 to 20) :

program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;

var
  number : integer;
begin
  for number := 1 to 20 do
    begin
      if Odd(number) then continue;
      writeln(number);
    end;
  readln;
end.

Example 2 (writing even numbers from 1 to 20) :

program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;

var
  number : integer;
begin
  for number := 1 to 20 do
    begin
      if not Odd(number) then continue;
      writeln(number);
    end;
  readln;
end.

You can download the complete code here.

Go to Previous Tutorial or Next Tutorial

5 comments:

  1. Is it me or have you reversed the logic of Odd/even?

    ReplyDelete
  2. supplier of 3D printing, rapid prototyping, rapid manufacturing, plastic fabrication, tooling, CNC and injection molding services.

    ReplyDelete
    Replies
    1. s The best and a lot of secret drop-shipping suppliers in the world which will provide your products globally available for you directly to your customers doors. Also get the best drop-shipping manufacturer on your organization.

      Delete
    2. thank you for the code , but i am still donnot get it, anyways if you wish high quality injection moulds form china please let me know

      Delete
  3. Our advantages:

    willing to deliver as quick as possible /AQAP (as quick as possible)
    western management led by industrial designers who will advise you the right technology.

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.