Example Program
  1. comment ALGOL 60 Example Program
  2. Input: An integer, listlen, where listlen is less than
  3. 100, followed by listlen-integer values
  4. Output: The number of input values that are greater than
  5. the average of all the input values ;
  6. begin
  7. integer array intlist [1:99];
  8. 2.5 The First Step Toward Sophistication: ALGOL 60 5758 Chapter 2 Evolution of the Major Programming Languages
  9. integer listlen, counter, sum, average, result;
  10. sum := 0;
  11. result := 0;
  12. readint (listlen);
  13. if (listlen > 0) (listlen < 100) then
  14. begin
  15. comment Read input into an array and compute the average;
  16. for counter := 1 step 1 until listlen do
  17. begin
  18. readint (intlist[counter]);
  19. sum := sum + intlist[counter]
  20. end;
  21. comment Compute the average;
  22. average := sum / listlen;
  23. comment Count the input values that are > average;
  24. for counter := 1 step 1 until listlen do
  25. if intlist[counter] > average
  26. then result := result + 1;
  27. comment Print result;
  28. printstring("The number of values > average is:");
  29. printint (result)
  30. end
  31. else
  32. printstring ("Error—input list length is not legal";
  33. end


Readability Example - Algol 68

The contributions of ALGOL 68 to the field of computer science have been deep, wide enduring, although many of these contributions were only publicly identified when they had reappeared in subsequently developed programming languages. Some ALGOL 68 features include expression-based syntax, user-declared types and structures/tagged-unions, a reference model of variables and reference parameters, string, array and matrix slicing, and also concurrency.

The main aims and principles of design of ALGOL 68:

  • Completeness and clarity of description
  • Orthogonal design
  • Security
  • Efficiency

The following code solves for the Quadratic equation. The code is proper, but good luck finding a 16-bit machine to compile it on.

  1. PROC print root = (INT ind, LONG COMPL x)VOID:
  2. ( print(("x", ind, " := "));
  3.  
  4. IF ABS(im OF x) < 1E-6 THEN
  5. print((re OF x, new line))
  6. ELSE print((x, new line))
  7. FI
  8. );
  9.  
  10. main:
  11. ( LONG COMPL a, b, c, d, x1, x2;
  12.  
  13. print(("a := "));
  14. read((a));
  15.  
  16. IF ABS a <1E-3 THEN
  17. print(( "Not a quadratic equation", new line));
  18. stop
  19. FI;
  20.  
  21. print(("b := "));
  22. read((b));
  23. print(("c := "));
  24. read((c));
  25.  
  26. a *:= 2;
  27. d := b*b-a*c*2.0;
  28.  
  29. IF ABS d <1E-3 THEN
  30. print(("x := ", re OF (-b/a)))
  31. ELSE
  32. print root(1, (-b+long complex sqrt(d))/a);
  33. print root(2, (-b-long complex sqrt(d))/a)
  34. FI
  35. )