Aún no tienes acceso a esta clase

Crea una cuenta y continúa viendo este curso

Ciclo for-in

22/33
Recursos

Aportes 25

Preguntas 1

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.

😎

en inglés stride = a long, decisive step (un paso largo y decisivo/firme) 😉

// Reto
// contar horas del dias partiendo desde 0 hasta 24, solo marque cada 3

let initialTime = 0
let endTime = 24
let intervalTime = 3
var timeCount = 0

print("*********")
for tickMark in stride(from: initialTime, to: endTime, by: intervalTime) {
    print("Hour: \(tickMark):00")
}
//Ejercicio 
for hours in stride(from: 0, to: 25, by: 3)
{
    if hours == 0
    {
        print("12 : 00 am")
    }else
    {
        if hours < 12
        {
            print("\(hours) : 00 am")
        }else
        {
            if hours - 12 == 0
            {
                print("12 : 00 pm")
            }else
            {
                print("\(hours - 12) : 00 pm")
            }
        }
    }
}
/*OUTPUT
12 : 00 am
3 : 00 am
6 : 00 am
9 : 00 am
12 : 00 pm
3 : 00 pm
6 : 00 pm
9 : 00 pm
12 : 00 pm
*/

let intervalTime = 1

for tickMark in stride(from: 0, through: 23, by: intervalTime) {
    if tickMark < 12 {
        print("\(tickMark) AM")
    } else {
        print("\(tickMark) PM")
    }

}```

Many examples of this course shown by teacher, are in “The Swift Programming Language” book in Books Store of Apple.

print("----------------------------")
let hours = 12
let hourInterval = 3
for tickTack in stride(from: 3, through: hours, by: hourInterval) {
print(“tickTack: (tickTack)”)
}

// si no quiero usar el iterador del for:
for _ in 1...5{
    print("Hola mundo!")
}

// si no quiero ir de uno en uno:
for _ in stride(from: 0, to: 5, by: 2){
    print("Gaa!")
}

let hours = 24
let hourInterval = 3
for time in stride(from: 0, to: hours, by: hourInterval){
    if time >= 12 {
        print("\(time):00 pm")
    }else{
        print("\(time):00 am")
    }
}

Quise “simular” un reloj, contando las 24 horas de día contando solo minutos de 5 en 5, espero sirva de aporte para alguien c:

for time in 0..<24{
    for currentMinute in stride(from: 0, to: 60, by: 5){
        print("\(hour) : \(currentMinute)")
    }
    hour += 1;
}
for i in stride(from: 0, to: 24, by: 3) {
    if i < 12 { print("0\(i) : 00 AM") } else {
        print("\(i) : 00 PM" )
    }
}
let hours = 24
let hourInterval = 3
var startTime = 0

for time in stride(from: startTime, to: hours, by: hourInterval) {
    if time <= 9 {
        print("La hora es \(time):00 am")
    } else {
        print("La hora es \(time):00 pm")
    }
}
var interval = 3
var limit = 21

for i in stride(from: 0, through: limit, by: interval){
   
    print(String(format: "%02d", i)+((i<12) ? ":00 am":":00 pm"))
    
}




Reto del reloj

//Reto hacer un reloj de 24 hrs que solo muestre cada 3
let hourDay = 24
let intervalHour = 3

for clock in stride(from: 0, to: hourDay, by: intervalHour){
    print("\(clock) : 00")
}```
//reto
var finalHour = 24
let hoursInterval = 3
for tickMark in stride(from: 0, to: finalHour, by: hoursInterval){
    print("\(tickMark) : 00")
}

RETO:

let initialTime = 0
let intervalTime = 3
let endTime = 24
var timeCount = 0
let emojis = ["🕕", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚","🕕", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚"]

for ticMark in stride(from: initialTime, to: endTime, by: intervalTime) {
    print("The hour is: \(ticMark):00 \(emojis[ticMark])")
}
let hours = 24
var startHour = 0
let hourInterval = 3
for tickMark in stride(from: 0, to: hours, by: hourInterval) {
    print("hour: \(tickMark)")
}
let am_pm = 12
let minute = 01
let hourInterval = 3

for hourRing in stride(from: 0, to: am_pm, by: hourInterval){
    print("0\(hourRing) : 0\(minute)")
}

![](

let day = 24
let hourInterval = 3
for hourMark in stride(from: 0, to: day, by:hourInterval){
    if (hourMark < 12){
        print("Son las: \(hourMark): 00 am")
    }else{
        print("Son las: \(hourMark): 00 pm")
    }
}```
//Reto de horas
let initialTime = 0
let endTime = 24
let secondTtimeInterval = 3
for hora in stride(from: initialTime, to: endTime, by: secondTtimeInterval){
    if hora<12 {
        print("Son las \(hora):00am ")
    }else if hora == 12{
        print("Son las \(hora):00pm")
    } else{
        print("Son las \(hora-12):00pm")
    }
}
let baseUnicodeClock = "1F55"
var validCodeString = baseUnicodeClock + "B"
var validUnicodeScalarValue = Int(validCodeString, radix: 16)!
var validUnicodeScalar = Unicode.Scalar(validUnicodeScalarValue)!
var hourBase = 0

for hour in 0...24 {
    hourBase = hour
    if hour > 12 {
        hourBase = hourBase - 12
    }
    
    if hourBase == 0 || hourBase == 12 {
        validCodeString = baseUnicodeClock + "B"
    } else if hourBase == 11 {
        validCodeString = baseUnicodeClock + "A"
    } else {
        validCodeString = baseUnicodeClock + String(hourBase - 1)
    }
    validUnicodeScalarValue = Int(validCodeString, radix: 16)!
    validUnicodeScalar = Unicode.Scalar(validUnicodeScalarValue)!

    for minute in stride(from:0,to: 60,by: 15) {
        print("\(hour):\(minute == 0 ? "00" : String(minute)) \(validUnicodeScalar)")
    }
}```
var endHour = 26
let minute = 60
let minuteIntervale = 5
let hourIntevarle = 3

for tickMarkHour in stride(from: 0, to: endHour, by: hourIntevarle) {
//    print("\(tickMarkHour) : 00")
    for tickMarck in stride(from: 0, to: minute, by: minuteIntervale) {
        if tickMarkHour <= 9 {
            print("\(tickMarkHour) : \(tickMarck) AM")
        }else {
            print("\(tickMarkHour) : \(tickMarck) PM")
        }
        
    }
}

Con un ternario 😎