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

iOS Swift Collections and Control Flow Control Flow With Conditional Statements Working With Logical Operators

Nigel Matheson
PLUS
Nigel Matheson
Courses Plus Student 1,166 Points

trouble breaking down questions

Is there any program or book i can get to help break down these questions cause I'm having trouble doing so?

Thanks

operators.swift
var results: [Int] = []

for n in 1...100 {
    // Enter your code below
    if n==
    // End code 
}

3 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

The concepts are broken down in the videos. I can break down this one for you:

The task request that you write an IF statement to check what the task is asking. You are going to use the modulus operator for both checks. The first check is used to see if the numbers in 1...100 are not equal to 0 which would make them an odd number. We then use the double && meaning "and" to check if the the numbers 1...100 are multiples of 7. Finally if the number meets both criteria we append the value to the results array that was given to us.

var results: [Int] = []

for n in 1...100 {
    // Enter your code below


    if n % 2 != 0 && n % 7 == 0 {

    results.append(n)

    }

    // End code 
}
Nigel Matheson
PLUS
Nigel Matheson
Courses Plus Student 1,166 Points

Hi thanks for that

What gets this answer - if n % 2 != 0 && n % 7 == 0 {

results.append(n) isn't anywhere in the learning video and thats confusing, am I doing something wrong or should I go back and learn some of the courses again?

Thanks

Jeff McDivitt
Jeff McDivitt
23,970 Points

To answer you first question

if n % 2 != 0 This will give you all of the odd numbers

n % 7 == 0 This will give you all the numbers that are divisible by 7

As for the append I thought it was covered but if not you can always check the documentation. Almost every programmer I know including myself relies heavily on the documentation, I would familirize yourself with it :)