mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Corrections and some added explanation.
This commit is contained in:
parent
5f49e0ade0
commit
912eca480e
@ -7,8 +7,9 @@ filename: learn.COB
|
||||
COBOL is a business-oriented language revised multiple times since its original design in 1960. It is claimed to still be used in over 80% of
|
||||
organizations.
|
||||
|
||||
```
|
||||
```cobol
|
||||
*COBOL. Coding like it's 1985.
|
||||
*Compiles with GnuCOBOL in OpenCobolIDE 4.7.6.
|
||||
|
||||
*COBOL has significant differences between legacy (COBOL-85)
|
||||
*and modern (COBOL-2002 and COBOL-2014) versions.
|
||||
@ -40,7 +41,7 @@ organizations.
|
||||
01 age picture 999. *> A number up to 3 digits.
|
||||
01 valx picture 999. *> Another number up to 3 digits.
|
||||
01 inyear picture s9(7). *> S makes number signed.
|
||||
*> Brackets indicate 6 repeats of 9,
|
||||
*> Brackets indicate 7 repeats of 9,
|
||||
*> ie a 6 digit number (not an array).
|
||||
|
||||
*Now let's write some code.
|
||||
@ -69,13 +70,13 @@ organizations.
|
||||
*> Old style way: doesn't give an index.
|
||||
perform age times
|
||||
display "*" with no advancing *> Ie, no newline at end
|
||||
end-perform.
|
||||
end-perform
|
||||
display "." *> Output buffer isn't flushed until newline.
|
||||
|
||||
*> New style way: with an index.
|
||||
perform varying valx from 1 by 1 until valx > age
|
||||
display valx "-" with no advancing
|
||||
end-perform.
|
||||
end-perform
|
||||
display "."
|
||||
|
||||
*> If tests are still good old if tests.
|
||||
@ -99,6 +100,10 @@ organizations.
|
||||
|
||||
subparagraph. *> Marks the top of an internal subprogram.
|
||||
*> Shares variable score with its caller.
|
||||
|
||||
*> Read year from system timer.
|
||||
*> Remember the whole "year 2000 crisis"? The yyyyddd
|
||||
*> option was added in response to that.
|
||||
accept inyear from day yyyyddd.
|
||||
|
||||
*> We can do math step-by-step like this...
|
||||
@ -110,9 +115,6 @@ organizations.
|
||||
*> Or we can just use expressions.
|
||||
compute inyear = 1970 - inyear.
|
||||
|
||||
*> Note: if inyear has gone negative, its negativity will
|
||||
*> not appear when printed, because we didn't include an
|
||||
*> S (sign character) in the PICTURE.
|
||||
if inyear >= 0 then
|
||||
display "When you were " inyear ", " with no advancing
|
||||
else
|
||||
@ -121,9 +123,12 @@ organizations.
|
||||
end-if
|
||||
|
||||
display "COBOL was the most popular language in the world."
|
||||
.
|
||||
. *> You can put the final . on a new line if it's clearer.
|
||||
|
||||
|
||||
*If we want to use a subprogram, we use literally a subprogram.
|
||||
*This is the entire program layout, repeated for the
|
||||
*eratosthenes subroutine.
|
||||
identification division.
|
||||
program-id. eratosthenes.
|
||||
|
||||
@ -133,10 +138,12 @@ organizations.
|
||||
*We can declare a variable to use as an index for it at the
|
||||
*same time.
|
||||
01 sieve pic 9 occurs 999 times indexed by sa, sb.
|
||||
*> Standard cobol doesn't have a boolean type.
|
||||
01 pstart pic 999.
|
||||
01 counter pic 999.
|
||||
|
||||
*Our parameters have to be declared in the linkage section.
|
||||
*Their pictures must match the values they're called with.
|
||||
linkage section.
|
||||
01 maxvalue picture 999.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user