codingOL

Preliminary Pseudo-Compact Test

Aug 6th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. begin
  2.  
  3. define factorial(number) begin
  4. when (number < 1) do begin
  5. return 1;
  6. end ;
  7.  
  8. temp equal to number*factorial(number - 1);
  9. return temp;
  10. end
  11.  
  12. define exponent(base,exp) begin
  13. temp equal to base;
  14. where start = 1 until exp do begin
  15. base equal to base * temp;
  16. end ;
  17. return base;
  18. end
  19.  
  20. a equal to 0;
  21. b equal to 5;
  22. d equal to "END OF PROGRAM";
  23. e equal to 1;
  24. exampleBase equal to 3;
  25. exampleExp equal to 3;
  26.  
  27. printing("MATH EXPRESSIONS");
  28. printing("----------------");
  29.  
  30. write("3 raised to 3 (Function): ");
  31. answer equal to exponent(exampleBase,exampleExp);
  32. printing(answer);
  33.  
  34. write("RECURSIVE FUNCTION - The factorial of ");
  35. write(b);
  36. write(" is: ");
  37. c equal to factorial(b);
  38. printing(c);
  39.  
  40. write("ARRAY TEST - ");
  41. define list() begin
  42. return [7,8,9];
  43. end
  44. array equal to list();
  45. printing("array consists of 3 elements");
  46. write("element 1: "); printing(array[0]);
  47. write("element 2: "); printing(array[1]);
  48. write("element 3: "); printing(array[2]);
  49. write("element 1 + 2 = "); printing(array[0]+array[1]);
  50. write("element 2 * 3 = "); printing(array[1]*array[2]);
  51.  
  52. printing("WHILE CONSTRUCT: AS LONG AS (<expr>) DO BEGIN <code> END");
  53. as long as (a < 50) do begin
  54. a equal to a + 1;
  55. end ;
  56. printing(a);
  57.  
  58. printing("DO-WHILE LOOP CONSTRUCT: PERFORM BEGIN <code> END AS LONG AS (<expr>)");
  59. perform begin
  60. e equal to e + 3;
  61. printing(e);
  62. end as long as (e < 75) ;
  63.  
  64. f equal to 0;
  65. cond equal to 14;
  66.  
  67. printing("FOR LOOP CONSTRUCT: WHERE <counter start> UNTIL <number of iterations> DO BEGIN <code> END");
  68. where g = 0 until cond do begin
  69. f equal to f + 1;
  70. printing(f);
  71. end ;
  72.  
  73.  
  74.  
  75. return d;
  76. end
Advertisement
Add Comment
Please, Sign In to add comment