No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Aprende todo un fin de semana sin pagar una suscripci贸n 馃敟

Aprende todo un fin de semana sin pagar una suscripci贸n 馃敟

Reg铆strate

Comienza en:

0D
17H
21M
6S

Ciclo for-in

22/33
Recursos

Aportes 32

Preguntas 1

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

o inicia sesi贸n.

馃槑

en ingl茅s stride = a long, decisive step (un paso largo y decisivo/firme) 馃槈

Many examples of this course shown by teacher, are in 鈥淭he 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(鈥渢ickTack: (tickTack)鈥)
}

// 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 hh = 24
let interval = 3
var clocks: [Int: String] = [0:"馃暃", 3:"馃晵", 6:"馃晻", 9:"馃晿", 12:"馃暃", 15:"馃晵", 18:"馃晻", 21:"馃晿"]

for time in stride(from: 0, to: hh, by: interval) {
    if var clock = clocks[time] {
        clock += (time < 12) ? " am." : " pm."
        print("Hora: \(clock)")
    }
}

馃晵 Reto del reloj

El output:

C贸digo:

var clock = [Int : Int]()

for hour in stride(from: 3, to: 13, by: 3) {
    clock[hour] = hour
}

print("""
         \(clock[12]!)

    \(clock[9]!)    鈳     \(clock[3]!)
      
          \(clock[6]!)

""")

Aqu铆 esta mi reto, sencillo pero seguro ![](

Hice un programa para registrar clientes de lo que llevamos del curso la verdad es que me ha ayudado bastante.

//Un programa para administrar clientes
var clientes = [String]()

while(true){
    print("Selecciona una opci贸n")
    print("1. Agregar un cliente")
    print("2. Actualizar un cliente")
    print("3. Eliminar un cliente")
    print("4. Mostrar todos los clientes")
    print("5. Salir")
    print("Selecciona una opci贸n: ", terminator: "")
    if let opcion = readLine(){
        if opcion == "5"{
            break
        }
        switch opcion {
        case "1":
            print("Ingrese el nombre de su cliente: ", terminator: "")
            if let nombre = readLine(){
                clientes.append(nombre)
            }
        case "2":
            print("Ingrese la posici贸n a actualizar: ")
            if let posicion = readLine(),
               let posicionInt = Int(posicion),
               clientes.indices.contains(posicionInt){
                print("Ingrese el nombre de la persona a actualizar: ", terminator: "")
                if let nombre = readLine(){
                    print("Se actualizo el cliente \(clientes[posicionInt]) por: \(nombre)")
                    clientes.insert(nombre, at: posicionInt)
                }
            }
            else{
                print("Posici贸n no v谩lida")
            }
        case "3":
            print("Ingresa la posici贸n a eliminar: ", terminator: "")
            if let posicion = readLine(),
               let posicionInt = Int(posicion),
               clientes.indices.contains(posicionInt){
                print("Cliente \(clientes[posicionInt]) ah sido eliminado!")
                clientes.remove(at: posicionInt)
            }
            else {
                print("Posici贸n no v谩lida")
            }
        case "4":
            for (idx, cliente) in clientes.enumerated(){
                print("\(idx+1): \(cliente)")
            }
        default:
            print("Opcion no valida")
        }
    }
}

Le agregu茅 los grados que ha rotado la manecilla

var militaryClock = 24
let hourInterval = 3
var degreesNeedle = 0
var turnEquivalent: String

for handClock in stride(from: 0, through: militaryClock, by: hourInterval) {
    if handClock <= 9 {
        var zeroLead = "0"
        print(zeroLead, terminator: "")
    }
    
    print("\(handClock):00, handclock has rotated \(degreesNeedle)掳")
    degreesNeedle += 90
}
var hours = 27
let hoursInterval = 3

for hourPlatzi in stride(from: 0, to: hours, by: hoursInterval){
    print("\(hourPlatzi)")
}



let hour = 9
let minutes = 60
let minuteInterval = 15
for ticMark in stride(from: 0, to: minutes, by: minuteInterval){
    print("\(hour): \(ticMark)")
}

let intervalTime = 1

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

}```
// 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 鈥渟imular鈥 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 馃槑