Pure Programmer
Blue Matrix


Cluster Map

Selection

L1

This page is under construction. Please come back later.

Selection1.swift
#!/usr/bin/env swift;
import Foundation

func main() -> Void {
	print("Start...")
	if CommandLine.arguments.count != 3 {
		print("You need at least two command line arguments!")
	}
	print("Finish...")
	exit(EXIT_SUCCESS)
}
main()

Output
Start... You need at least two command line arguments! Finish... Start... Finish...
Selection2.swift
#!/usr/bin/env swift;
import Foundation
import Utils

func main() -> Void {
	let x:Int = Int(CommandLine.arguments[1]) ?? 0
	print("Start...")
	if x > 10 {
		print("Greater than 10")
	} else {
		print("Less than or equal to 10")
	}
	print("Finish...")
	exit(EXIT_SUCCESS)
}
main()

Output
Start... Less than or equal to 10 Finish... Start... Greater than 10 Finish...
Selection3.swift
#!/usr/bin/env swift;
import Foundation
import Utils

func main() -> Void {
	let x:Int = Int(CommandLine.arguments[1]) ?? 0
	print("Start...")
	if x > 1000 {
		print("Greater than 1000")
	} else if x > 100 {
		print("Greater than 100 but less than or equal to 1000")
	} else {
		print("Less than or equal to 100")
	}
	print("Finish...")
	exit(EXIT_SUCCESS)
}
main()

Output
Start... Less than or equal to 100 Finish... Start... Greater than 100 but less than or equal to 1000 Finish... Start... Greater than 1000 Finish...
Selection4.swift
#!/usr/bin/env swift;
import Foundation
import Utils

func main() -> Void {
	let x:Int = Int(CommandLine.arguments[1]) ?? 0
	switch x {
		case 1:
			print("One")
		case 2:
			print("Two")
		case 3, 4:
			print("Three or Four")
		default:
			print("Just don't know!")
	}
	exit(EXIT_SUCCESS)
}
main()

Output
Just don't know! One Two Three or Four Three or Four
Selection5.swift
#!/usr/bin/env swift;
import Foundation
import Utils

func main() -> Void {
	var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1)
	x = x.lowercased()
	switch x {
		case "a", "e", "i", "o", "u":
			print(Utils.format("{0:c} is a vowel", Utils.ord(x)))
		case "y":
			print("y is sometimes a vowel")
		default:
			print(Utils.format("{0:c} is a consonant", Utils.ord(x)))
	}
	exit(EXIT_SUCCESS)
}
main()

Output
Selection5.swift:6:26: error: cannot convert value of type 'String' to specified type 'Character' 4 | 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) | `- error: cannot convert value of type 'String' to specified type 'Character' 7 | x = x.lowercased() 8 | switch x { Selection5.swift:7:8: error: cannot assign value of type 'String' to type 'Character' 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) 7 | x = x.lowercased() | `- error: cannot assign value of type 'String' to type 'Character' 8 | switch x { 9 | case "a", "e", "i", "o", "u": Selection5.swift:6:26: error: cannot convert value of type 'String' to specified type 'Character' 4 | 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) | `- error: cannot convert value of type 'String' to specified type 'Character' 7 | x = x.lowercased() 8 | switch x { Selection5.swift:7:8: error: cannot assign value of type 'String' to type 'Character' 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) 7 | x = x.lowercased() | `- error: cannot assign value of type 'String' to type 'Character' 8 | switch x { 9 | case "a", "e", "i", "o", "u": Selection5.swift:6:26: error: cannot convert value of type 'String' to specified type 'Character' 4 | 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) | `- error: cannot convert value of type 'String' to specified type 'Character' 7 | x = x.lowercased() 8 | switch x { Selection5.swift:7:8: error: cannot assign value of type 'String' to type 'Character' 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) 7 | x = x.lowercased() | `- error: cannot assign value of type 'String' to type 'Character' 8 | switch x { 9 | case "a", "e", "i", "o", "u": Selection5.swift:6:26: error: cannot convert value of type 'String' to specified type 'Character' 4 | 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) | `- error: cannot convert value of type 'String' to specified type 'Character' 7 | x = x.lowercased() 8 | switch x { Selection5.swift:7:8: error: cannot assign value of type 'String' to type 'Character' 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) 7 | x = x.lowercased() | `- error: cannot assign value of type 'String' to type 'Character' 8 | switch x { 9 | case "a", "e", "i", "o", "u": Selection5.swift:6:26: error: cannot convert value of type 'String' to specified type 'Character' 4 | 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) | `- error: cannot convert value of type 'String' to specified type 'Character' 7 | x = x.lowercased() 8 | switch x { Selection5.swift:7:8: error: cannot assign value of type 'String' to type 'Character' 5 | func main() -> Void { 6 | var x:Character = Utils.substr(CommandLine.arguments[1], 0, 1) 7 | x = x.lowercased() | `- error: cannot assign value of type 'String' to type 'Character' 8 | switch x { 9 | case "a", "e", "i", "o", "u":
swift

Questions

Projects

More ★'s indicate higher difficulty level.

References