
通常、新しいトーゴのベストランゲージの支持者は、次のようなものを学習および宣伝するための独自の広告ミニプログラムを作成します。
ageOfBob = 0
ageOfMary = 0
print("Input Bob's age: ")
read(ageOfBob)
print("Input Marry's age: ")
read(ageOfMary)
// Do the math
if (ageOfBob > ageOfMary)
print("Bob is older than Mary by ", ageOfBob - ageOfMary, " years")
else if (ageOfBob < ageOfMary)
print("Mary is older than Bob by ", ageOfMary - ageOfBob, " years")
else
print("Mary and Bob are of the same age")
, , , C- , , .
---, , , :
const MAX_PERSON_AGE = 120
const MIN_PERSON_AGE = 1
int getAge(string name) {
age = 0
print("Input ", name, "'s age: ")
read(age)
if (age < MIN_PERSON_AGE or age > MAX_PERSON_AGE)
throw IncorrectAgeInputException
else
return age
}
try {
ageOfBob = getAge("Bob")
ageOfMary = getAge("Mary")
} catch (IncorrectAgeInputException) {
print("You're doing it wrong!")
}
// Do the math
...
( — ) ( Don't Repeat Yourself), , . , getAge
unit-…
, , , .
, .
Ada. Ada 1983- " , ", Haskell Rust. Ada native- , . …
with ada.text_io, ada.integer_text_io, ada.io_exceptions;
use ada.text_io;
procedure main is
type Age is range 1 .. 120;
package io is new ada.text_io.integer_io(num => Age);
ageOfBob, ageOfMary : Age;
begin
put_line("Input Bob's age: ");
io.get(ageOfBob);
put_line("Input Mary's age: ");
io.get(ageOfMary);
-- Do the math
if ageOfBob > ageOfMary then
put_line("Bob is older than Mary by" & Age'Image(ageOfBob - ageOfMary) & " years");
elsif ageOfBob < ageOfMary then
put_line("Mary is older than Bob by" & Age'Image(ageOfMary - ageOfBob) & " years");
elsif ageOfBob = ageOfMary then
put_line("Mary and Bob are of the same age");
end if;
exception
when ada.io_exceptions.Data_Error =>
put_line("You're doing it wrong!");
when others => null;
end main;
Age
:
type Age is range 1 .. 120;
ada.text_io.integer_io
, :
package io is new ada.text_io.integer_io(num => Age);
io.get(ageVar)
, ageVar
— Age
, , Age
, Data_Error
.
Ada , . , "" , "" , , .