Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- // Set a flag to determine if the user is cheating
- var isCheating = false
- // Define a function to check if the user is cheating
- func checkForCheats(input: String) {
- // Set a list of cheats
- let cheats = ["cheat1", "cheat2", "cheat3"]
- // Iterate through the list of cheats
- for cheat in cheats {
- // If the input contains a cheat, set the flag to true and break out of the loop
- if input.contains(cheat) {
- isCheating = true
- break
- }
- }
- }
- // Prompt the user for input
- print("Enter a command: ", terminator: "")
- if let userInput = readLine() {
- // Check if the user is cheating
- checkForCheats(input: userInput)
- // If the user is cheating, display a message and exit the program
- if isCheating {
- print("Cheating is not allowed!")
- exit(0)
- }
- // If the user is not cheating, continue with the program
- print("Valid input")
- }
Add Comment
Please, Sign In to add comment