xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Docs/Examples/guess_example.txt (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1The following is a demonstration of the guess.d script,
2
3
4guess.d is a guessing game written in DTrace. It goes like this,
5
6   # ./guess.d
7   guess.d - Guess a number between 1 and 100
8
9   Enter guess 1: 50
10   Lower...
11   Enter guess 2: 25
12   Higher...
13   Enter guess 3: 37
14   Higher...
15   Enter guess 4: 44
16   Higher...
17   Enter guess 5: 48
18   Lower...
19   Enter guess 6: 46
20   Lower...
21   Enter guess 7: 45
22   Correct! That took 7 guesses.
23
24   Please enter your name: Brendan Gregg
25
26   Previous high scores,
27   Fred Nurk 7
28   Brendan Gregg 7
29
30It was written as a demonstration of the same code written in dozens of
31languages. It makes a good demonstration, as it covers integer and string
32variables, conditional statements, loops, keyboard input, screen output,
33and file input and output.
34
35Written in DTrace however, is not such a good demonstration! DTrace doesn't
36have loops (it doesn't really need them either) which made the code a
37little odd. DTrace also doesn't have keyboard input... So this script is
38somewhat amusing as an example, but not terribly useful.
39
40