Keyboard input/Obtain a Y or N response: Difference between revisions

→‎Tcl: Added implementation
m (→‎{{header|PureBasic}}: Cleaned up code & improved comments)
(→‎Tcl: Added implementation)
Line 30:
Until Key$="Y" Or Key$="N"
PrintN("The response was "+Key$)</lang>
 
=={{header|Tcl}}==
<lang tcl>proc yesno {{message "Press Y or N to continue"}} {
fconfigure stdin -blocking 0
exec stty raw
read stdin ; # flush
puts -nonewline "${message}: "
flush stdout
while {![eof stdin]} {
set c [string tolower [read stdin 1]]
if {$c eq "y" || $c eq "n"} break
}
puts [string toupper $c]
exec stty -raw
fconfigure stdin -blocking 1
return [expr {$c eq "y"}]
}
 
set yn [yesno "Do you like programming (Y/N)"]</lang>
Anonymous user