Thursday, 13 May 2010

if Statement in Delphi ( Delphi Tutorial # 9 )

There are two kinds of conditional statement : if statement and case statement. This both statements are for making decisions that involve two or more alternative choices or conditions.

In this tutorial, we will learn about if statement. There are two kinds of if statement :

-         if ….. then

-         if ….. then …. else

The syntax of if …. then statement is :

     If boolean expression then statement;

Boolean expression can be true or false. If it is true, computer will execute the statement. If it is false, computer will not execute the statement.

The syntax of if …. then …. else statement is :

     If boolean expression then first_statement else second_statement;

If boolean expression is true, computer will execute the first statement. If it is false, computer will execute the second statement.

The flowchart of if statement is below :

Example for if …. then statement :


program Project1;

{$APPTYPE CONSOLE}

uses SysUtils;

var

 score : integer;

begin

  write('Your score : ');

  readln(score);

  if score < 60 then writeln('You did not pass the exam');

  if score >= 60 then writeln('You passed the exam');

  readln;

end.


Example for if …. then …. else statement :


program Project2;

{$APPTYPE CONSOLE}

uses

  SysUtils;

var

 score : integer;

begin

  write('Your score : ');

  readln(score);

  if score < 60 then

    writeln('You did not pass the exam')

   else

    writeln('You passed the exam');

  readln;

end.

 

Both projects above will give you the same result.

Go to Previous Tutorial or Next Tutorial

7 comments:

  1. Hiya! Do you happen to know how to verify that the content of your site is exclusive around the blogosphere and no other person is using it without making sure you are aware of it?

    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
  3. We hebben ervaring in familie matrijzen, multi cavity matrijzen, meervoudige matrijzen, matrijzen met sliders. moulds voor insertmolding en matrijzen voor plastics, tpe/tpre rubbers en siliconen..

    ReplyDelete
  4. We love IGES IGS STEP or Parasolid files of your rapid prototype

    if you don not have your Cadfile finished we can assist you with creating 3dcadfiles which are necessity to program our sophisticated machinery.

    ReplyDelete
    Replies
    1. Prototype is a Rapid Prototyping manufacturer in China mainland close to Hong Kong, our rapid prototyping services include: CNC, SLA,

      Delete

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.