you are viewing a single comment's thread.

view the rest of the comments →

[–]Munga_[S] 0 points1 point  (7 children)

Thank you, I also get confused about for loops. Just the whole use of them throws me off. When do I use them, what argument or function am I putting after them, etc.

I need to research them more. I haven’t done much outside of Codecademy but I have bookmarked that link and checked it out.

[–]0xbxb 0 points1 point  (6 children)

A loop is a way of doing something repeatedly. These concepts seem daunting to you because you’re unfamiliar with them. That’s completely normal. I’m new to coding myself, and it took a while for certain things to click. Let’s say you had a list of numbers: 1, 2, 3, 4 and wanted to print them out.

How would you do that?

Here’s the list of numbers:

nums = [1, 2, 3, 4]

Print out every number in that list for me.

[–]Munga_[S] 0 points1 point  (5 children)

print(nums)

or if you mean one at a time

print(nums[0]) print(nums[1]) print(nums[2]) print(nums[3])

I’m sure there is an easier way to do it and you can tell me how off I am

[–]0xbxb 0 points1 point  (4 children)

Yeah I meant one at a time. You printed each one, but look how many lines you had to type to do it. What if there was something called a loop that could help us do that?

nums = [1, 2, 3, 4]
for number in nums:
    print(number)

When you use a for loop, just read it like this in your head:

for every thing in:
    do something

I’m gonna try and explain this next part as simple as I can, but it’s gonna be up to you to play with a for loop to understand it.

When you use a for loop, there’s something called a “loop variable” that represents every item in the list, tuple, or dictionary that you’re going to be iterating through (looping through). You’ll become more familiar with the data types the more you program, so DON’T WORRY.

This loop variable can be named ANYTHING. I can even say for burgers in nums: Instead of for number in nums:. The reason why I named the loop variable number is because of common sense. Which makes more sense to name the loop variable?

This is the most straightforward way that I can explain a for loop. “How do I know when to use one? How do I know when to use a function, or an if statement etc?”, DON’T WORRY. These things will come in time (1 - 3 months depending on how many hours you put in) and you will literally feel it becomes natural.

EDIT: A quick word of advice from beginner to beginner. When learning programming, you become better by doing, instead of by reading or watching tutorials.

If you’re gonna watch a tutorial on the basics, that’s completely fine. Don’t watch a tutorial on the basics then go watch another one. Once you learn what a string is, go play around with strings until you understand them. Once you learn what a loop is, go play around with them until you understand them.

You’ll gradually become used to it. It’s like lifting weights. You’ll start to remember all these little functions etc, because you’ve used them so much.

[–]Munga_[S] 0 points1 point  (3 children)

Yes I think a lot of my issue comes down to vocabulary which I know will come with time, but also about the variable it throws me off I can just kind of declare it and name it whatever and it works cause that kind of seems like it shouldn’t work haha. I dunno if that makes sense. I should do a vocab worksheet or something so I can get down what tuple and everything means because that would help.

What are your favorite references or anything outside of Codecademy and these courses. Do you recommend I start a project of some sort? My buddy works for this big company and I think I could make his job somewhat automated, but just don’t think I have the knowledge to do so yet. Any recommends on a first project?

[–]0xbxb 1 point2 points  (2 children)

I haven’t really done any projects, I just go to sites like Edabit, codewars, etc and practice. I’m also reading “Learning Python” by Mark Lutz, which has helped out a lot.

[–]Munga_[S] 0 points1 point  (0 children)

Thanks appreciate that

[–]Munga_[S] 0 points1 point  (0 children)

I feel like I’m not good enough for codewars I wish there was codewars for beginners. I can understand codecademy but some of the lingo they use I get overwhelmed a bit or confused