Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Benjamin Butterworth
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Benjamin Butterworth
iOS Development with Swift Techdegree Graduate 14,418 Points

iOS Control Flow Decomposition of Problems

Hello - please disregard the name I take my education on Swift seriously ;)

I need help with generating the body of control flow statements based on a goal or exercise problem. For example:

You are given a number. Decompose number into prime factor and write it as an expression.

var number = 10 print("(number) = ", terminator: "")

var isFirst = true // how did you deduce to declare this variable?

// the i is the first value in the sequence, the 2...number is the range of sequence. I get that. But how do you deduce the rest of the body of the loop??

for i in 2...number { if number % i == 0 { while (number % i == 0) { number /= i

        if isFirst {
            isFirst = false
        } else {
            print(" * ", terminator: "")
        }

        print(i, terminator: "")
    }
}

}