92 lines
2 KiB
Swift
92 lines
2 KiB
Swift
import SwiftUI
|
|
|
|
import Playgrounds
|
|
import Foundation
|
|
|
|
struct RangeView: TabContent {
|
|
init() {
|
|
texte = []
|
|
}
|
|
|
|
static var title = "Ranges"
|
|
static var image = "list.bullet"
|
|
|
|
@State var texte: [String]
|
|
|
|
var body: some View {
|
|
List(2...16, id: \.self) { i in
|
|
HStack(spacing:0){
|
|
Text("\(i)")
|
|
if i.isMultiple(of: 3) { Text("Fizz")}
|
|
|
|
if i.isMultiple(of: 5) { Text("Buzz")}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#Playground {
|
|
var students = ["Bill", "Linus"]
|
|
let size = [1.65, 1.79]
|
|
|
|
func calendartest(){
|
|
let born = 1973
|
|
let calendar = Calendar.current
|
|
let components = calendar.dateComponents([.year], from: Date())
|
|
if let today = components.year
|
|
{
|
|
for year in 2020...2035 {
|
|
if today > year {
|
|
print ("\(year) war ich \(year-born) Jahre alt")
|
|
}
|
|
else if today < year {
|
|
print ("\(year) werde ich \(year-born) Jahre alt")
|
|
|
|
} else {
|
|
print ("\(year) bin ich \(year-born) Jahre alt")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
func whilecount(){
|
|
var countdown = Int.random(in: 1...100)
|
|
while countdown < 100 {
|
|
countdown+=1
|
|
print ("Bin bei \(countdown)")
|
|
}
|
|
print ("done: CD = \(countdown)")
|
|
}
|
|
|
|
func while_test(){
|
|
var r = 0
|
|
var c = 0
|
|
while r != 100 {
|
|
r = Int.random(in: 1...100)
|
|
c+=1
|
|
print ("würfel mit W100: \(r)")
|
|
}
|
|
print ("done: hab nach \(c) Versuchen \(r) gewürfelt")
|
|
}
|
|
func fizzbuzz(){
|
|
var i = 1
|
|
while i < 16 {
|
|
if i.isMultiple(of: 3){
|
|
print( "Fizz")}
|
|
if i.isMultiple(of: 5){
|
|
print( "Buzz")}
|
|
else{
|
|
print (i)
|
|
}
|
|
}
|
|
}
|
|
|
|
fizzbuzz()
|
|
}
|
|
|
|
|
|
#Preview {
|
|
RangeView()
|
|
}
|