Difference between revisions of "Code Snippet: Prompt for Yes or No"
From Coder Merlin
(Created page with "// Prompt the user for 'yes' or 'no' var line : String? repeat { print("Please enter 'yes' or 'no' ->", terminator:"") line = readLine() } while (line == nil || (lin...") |
|||
Line 1: | Line 1: | ||
== Read the contents of a file into a string == | |||
<syntaxhighlight lang="swift"> | |||
// Prompt the user for 'yes' or 'no' | // Prompt the user for 'yes' or 'no' | ||
var line : String? | var line : String? | ||
Line 7: | Line 9: | ||
// By the time we get here, line! is either "yes" or "no" | // By the time we get here, line! is either "yes" or "no" | ||
</syntaxhighlight> |
Revision as of 15:08, 6 December 2018
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Read the contents of a file into a string[edit]
// Prompt the user for 'yes' or 'no'
var line : String?
repeat {
print("Please enter 'yes' or 'no' ->", terminator:"")
line = readLine()
} while (line == nil || (line! != "yes" && line! != "no"))
// By the time we get here, line! is either "yes" or "no"