Iteration
This page is under construction. Please come back later.
#!/usr/bin/env swift; import Foundation import Utils // Begin Main var max:Int = 5 if CommandLine.arguments.count == 2 { max = Int(CommandLine.arguments[1]) ?? 5 } for _:Int in 0..<max { print("Hello, world!") } exit(EXIT_SUCCESS)
Output
$ swiftc Iteration1.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation // Begin Main for i:Int in stride(from: 10, through: 1, by: -1) { print(String(i)) } print("Blastoff!") exit(EXIT_SUCCESS)
Output
$ swiftc Iteration2.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation // Begin Main print("Even numbers up to 100...") for i:Int in stride(from: 2, through: 100, by: 2) { print(String(i)) } exit(EXIT_SUCCESS)
Output
$ swiftc Iteration3.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation // Begin Main print("Floating point numbers") for d:Double in stride(from: 1.0, to: 2.01, by: 0.1) { print(String(d)) } exit(EXIT_SUCCESS)
Output
$ swiftc Iteration4.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation // Begin Main print("Powers of 2 up to 256!") var i:Int = 1 while i <= 256 { print(String(i)) i *= 2 } exit(EXIT_SUCCESS)
Output
$ swiftc Iteration5.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation // Begin Main var s:String = "Hello, world! 🥰🇺🇸" for c in s { print(String(c)) } exit(EXIT_SUCCESS)
Output
$ swiftc Iteration6.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Iterators
swiftQuestions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
- Amortization Table
- Amortization Table (Revisited)
- Blackboard
- Blackboard (Revisited)
- Character Types
- Compute π (Monte Carlo)
- Floating Point Error
- ISBN-10 Check
- License Plate Generator
- Multiplication Table
- Number Guessing Game
- Punchcard Message
- Random Floats
- Random Integers
- Supermarket Sale
- Supermarket Sale (Revisited)
- Temperature Table
- Unicode Test
References
- [[Swift Community]]
- [[Swift Language Guide]]
- [[Swift Language Reference]]
- [[Swift Programming Language]], Apple Inc.
- [[Swift Doc]]
- [[We Heart Swift]]
- [[Swift Cookbook]]
- [[Swift Playground]]
- [[Swift at TutorialsPoint]]
- [[Hacking with Swift]]