Jump to content

User input/Text: Difference between revisions

m
→‎{{header|Tcl}}: small improvements/formatting
(→‎{{header|AutoHotkey}}: windows console example)
m (→‎{{header|Tcl}}: small improvements/formatting)
Line 494:
Like LISP, there is no concept of a "number" in TCL - the only real variable type is a string (whether a string might represent a number is a matter of interpretation of the string in a mathematical expression at some later time). Thus the input is the same for both tasks:
 
<lang tcl> set str [gets stdin]
set num [gets stdin]</lang>
 
possibly followed by something like
 
<lang tcl> if {![string is integer -strict $num]} then { ...do something here...}</lang>
 
If the requirement is to prompt until the user enters the integer 75000, then:
 
<lang tcl>set input 0
while {$input != 75000} {
Line 509 ⟶ 508:
set input [gets stdin]
}</lang>
 
or
Of course, it's nicer to wrap the primitives in a procedure:
<lang tcl>proc question {var message} {
upvar 1 $var v
Line 519:
question task "What is your quest"
question doom "What is the air-speed velocity of an unladen swallow"</lang>
 
 
=={{header|Toka}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.