Multiple questions for whoever is bored and helping a lost soul

  1. What is the purpose of a ‘for’ loop? I can choose multiple but according to what I’ve read via the swift book, its used to iterate through items in an array or list.

But....does it have other uses?

  1. which of these would allow you to control the flow of your application based on a case from the following enum? multiple could apply
    enum Language {
    case swift
    case objectiveC
    case rust
    case ruby
    A) if
    B) switch
    C) for loop
    D) protocol
    i think it’s loop only, which makes me nervous to press submit

  2. this one is frustrating because I know once it’s explained I’ll feel silly -
    Which is the correct way to write a string that reads “the width is 100”
    I said —
    let widthLabel = “The width is \ (100)”
    I’m right, right?

Is this homework for a class?

Have you studied the material that teaches these things?

Have you read The Swift Programming Language, or at least A Swift Tour?

1 Like

Hi, not homework. I’m self teaching and doing coding challenges online. As you can see, I did say what I was thinking the correct responses were as well under each question I had. I’ve been reading and learning and trying to receive some help or be pointed in the right direction for more help. Thank you

for _ in 0..<1_000_000 {
if language == .swift {

switch language {
case .swift:
case .objectiveC:
case .rust:
case .ruby:

Have fun.

Coding challenges will only take you so far. You really just need to write code until it becomes second nature. Once you are proficient, you need to learn about programming patterns to write larger programs. Finally, you need to learn about the engineering side of programming to make sure you are choosing the right patterns for performance. There is no shortcut. Read all you can. Don’t worry if you don’t understand it all at first. Take breaks and revisit topics you don’t fully understand. Each time it will make more sense until you get it. See what others are doing in their code and try to figure out why they are writing the way they do.

For #3, it looks like you have an extra space.