Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The VeryTime,Stay informed and read the latest news today from The VeryTime, the definitive source.

Turbo Pascal Tutorial

44

    Why Learn Turbo Pascal

    • If Turbo Pascal was dropped by its developer in 1995, why is it still in use? Turbo Pascal is a particularly good choice for introductory computer science courses due to its relative simplicity, as compared to modern languages and development environments such as Microsoft Visual Studio. This can be illustrated with the traditional first program, Hello World.

    Following Tradition: Hello World

    • The Turbo Pascal version of the classic Hello World program is refreshingly simple. Start Turbo Pascal, and in the text editor window, type the following code:

      begin
      writeln('Hello World');
      end.

      As always, when dealing with programming source code, small details in punctuation are important. Changing the single quotes around Hello World to double quotes will produce a syntax error, as will leaving out the semicolon at the end of the line or the period after "end."

      One thing you've already noticed if you are following along is that the Turbo Pascal development lacks any mouse support. That means, assuming you are in Windows, that you'll need to hold down the Alt key to get to the menu options for saving and running your programs. Learning to use key shortcuts when possible is a good habit to get into early in your programming career, and that's one reason Turbo Pascal is popular for introductory computer science courses. However, if you simply must have a mouse, along with more modern IDE enhancements such as syntax highlighting, the Turbo Pascal-compatible compiler Free Pascal has a more modern development environment called Lazarus (see Resources below).

    Variables and Input

    • Variables must be declared before the beginning of your program with syntax like the following:

      var
      myName : String[30];

      begin
      write('What is your first name? ');
      readln (myName);
      writeln('Hello ', myName);

      You'll notice some changes that have been made from the last program. You can choose between the functions "write" and "writeln" depending on whether you want to automatically have a new line started for us at the end of our output. In this case, you'll allow your users to write their names on the same line as the question. The difference between "read" and "readln," however, is somewhat counter-intuitive. Both will read all characters until the enter key is pressed. However, "readln" will move the cursor to the next line after enter is hit, whereas read will leave it where it is.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.