Pure Programmer
Blue Matrix


Cluster Map

Iteration

L1

This page is under construction. Please come back later.

Iteration1.swift
#!/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)
Iteration2.swift
#!/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)
Iteration3.swift
#!/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)
Iteration4.swift
#!/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)
Iteration5.swift
#!/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)
Iteration6.swift
#!/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

swift

Questions

Projects

More ★'s indicate higher difficulty level.

References