Created
March 20, 2016 15:21
-
-
Save aksiksi/11f8634379ca53db8037 to your computer and use it in GitHub Desktop.
Some Free Pascal...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program Hello; | |
uses sysutils; | |
// Record syntax | |
type Book = record | |
title: string; | |
author: string; | |
isbn: string; | |
end; | |
function max(x, y: integer): integer; | |
begin | |
if (x >= y) then | |
max := x | |
else | |
max := y; | |
end; | |
var i, j: integer; | |
var s: string; | |
var age: 10..100; | |
var ret: integer; | |
var b: Book; | |
var books: array [0..9] of Book; // Create array of 10 books | |
begin | |
writeln('Hello, world!'); | |
ret := max(10, 11); | |
writeln(ret); | |
b.title := 'Hey dude'; | |
b.author := 'Max'; | |
b.isbn := '1010031301301'; | |
writeln('Title = ', b.title, 'Author = ', b.author, 'ISBN = ', b.isbn); | |
// Now, create more books! | |
for i := 0 to 9 do | |
begin | |
b.title := 'Harry Potter ' + inttostr(i+1); | |
b.author := 'JK Rolling'; | |
b.isbn := 'N/A'; | |
books[i] := b; | |
end; | |
// Print them books | |
for i := 0 to 9 do writeln(books[i].title); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To compile this example, get Free Pascal.
Then navigate to the file's directory and run:
fpc hello.pas
You'll get a binary for your platform with the name
hello
.