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

Brandon Mahoney
Brandon Mahoney
iOS Development with Swift Techdegree Student 25,409 Points

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
6,119 Points

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