mirror of
https://github.com/Stichting-MINIX-Research-Foundation/netbsd.git
synced 2025-09-10 15:46:33 -04:00
40 lines
1.1 KiB
Plaintext
40 lines
1.1 KiB
Plaintext
The following is a demonstration of the guess.d script,
|
|
|
|
|
|
guess.d is a guessing game written in DTrace. It goes like this,
|
|
|
|
# ./guess.d
|
|
guess.d - Guess a number between 1 and 100
|
|
|
|
Enter guess 1: 50
|
|
Lower...
|
|
Enter guess 2: 25
|
|
Higher...
|
|
Enter guess 3: 37
|
|
Higher...
|
|
Enter guess 4: 44
|
|
Higher...
|
|
Enter guess 5: 48
|
|
Lower...
|
|
Enter guess 6: 46
|
|
Lower...
|
|
Enter guess 7: 45
|
|
Correct! That took 7 guesses.
|
|
|
|
Please enter your name: Brendan Gregg
|
|
|
|
Previous high scores,
|
|
Fred Nurk 7
|
|
Brendan Gregg 7
|
|
|
|
It was written as a demonstration of the same code written in dozens of
|
|
languages. It makes a good demonstration, as it covers integer and string
|
|
variables, conditional statements, loops, keyboard input, screen output,
|
|
and file input and output.
|
|
|
|
Written in DTrace however, is not such a good demonstration! DTrace doesn't
|
|
have loops (it doesn't really need them either) which made the code a
|
|
little odd. DTrace also doesn't have keyboard input... So this script is
|
|
somewhat amusing as an example, but not terribly useful.
|
|
|