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

s t
s t
949 Points

Advice regarding compatibility with Swift IOS course

I have no programming knowledge what so ever but I decided to change that so two days ago I took an introduction to Swift course (which I did with relative ease) over the past few days and then started working my way through the second course recommended. I have however hit a road block with understanding parts of how to write code for: for and while loops and using some of the logical operators such as && || ! % etc... all at once. Although when I'm watching the course videos I completely understand everything in its presented format I struggle to complete the tasks within the course or even understand the question.

put simply is it normal to have this issue or am I falling short intellectually to be able to understand programming?

are any of the you finding this course hard?

the current question I am on below seems way to hard to solve for me, even though i feel like I understood the course which proceeded it relatively well.

""For this challenge, we'd like to know in a range of values from 1 to 100, how many numbers are both odd, and a multiple of 7.

To start us off, I've written a for loop to iterate over the desired range of values and named the local constant n. Your job is to write an if statement inside the for loop to carry out the desired checks.

If the number is both an odd number and a multiple of 7, append the value to the results array provided.

Hint: To check for an odd number use the not operator to check for "not even""

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

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

    // End code 
}

3 Answers

It helps to talk yourself through code, often times you find you are just making it more difficult than it needed to be. Yes talking out loud will help so give it a try. As far as intellectually keep in mind you are literally rewiring your brain when you are learning. This isn't something that you just watch a video and it will automatically be a part of you. You have to build to really get it. Sometimes you won't and then one day you will wake up and be like what the heck how did I not get that. No joke its happened to me many times.

Think of it like this: So if the remainder of n / 2 isn't 0 and the remainder of n / 7 is 0 then do put n into results....

var results: [Int] = []

for n in 1...100 {
    // Enter your code below
    if n % 2 != 0 && n % 7 == 0 {
      results.append(n)
    }
    // End code 
}
s t
s t
949 Points

Hi Brandon, thanks for your positive comments. I suppose when being used to grasping complex concepts you just presume this will be another, but it appears its a lot more alien to the mode of rationality than I had originally anticipated. I will keep at it and hope that I can familiarise myself with Swift over time. Again thanks for your time and thoughts.

Harold Thompson
Harold Thompson
18,157 Points

Thanks Brandon for the positive comments and for explaining what you did. Both of them help me greatly.