Here's one approach to calculate prime numbers between 1 and 100 in Swift:
main.swift271 chars18 lines
This code defines a function isPrime
that checks whether a given number is prime or not by dividing it by numbers from 2 up to but not including the number itself. It then uses a loop to iterate over all numbers between 1 and 100, and prints out those that are prime. Note that there are more efficient algorithms for calculating primes, but this should work for small ranges of numbers.
gistlibby LogSnag