What's new

Closed Nahihirapan ako maunawaan yung Nested Looping

Status
Not open for further replies.

Arlertz

Eternal Poster
Joined
Jun 13, 2019
Posts
1,138
Reaction
379
Points
324
Hi guys! Inaaral ko po yung Python. Actually, sinubukan ko aralin yung JavaScript at C# noon pero huminto din ako dahil nahirapan ako maunawaan talaga yung nested looping. Tapos nahinto na naman ako. May work ako sa SEO company, pero yung ginagawa ko ay pakiramdam ko repeated tasks lang. Cool naman boss ko at mabait kaya relax ang work. Pero gusto ko talaga matutuhan yung programming kasi gusto ko makagawa ng program o web apps. Kaya sinimulan ko aralin ngayon yung Python kasi sabi madali daw siya sa lahat. Naiintindihan ko naman yung variables, if/else, conditional operator, at yung for and while loops kung isang loop lang. I mean

Python:
numbers = [8, 3, 5, 12, 21]

count = 0

for number in numbers:

    if number % 2 == 0:

        print(number)

        count += 1

if count > 1:

    print(f"You have {count} even numbers")

else:

    print(f"You have {count} even number")

Pag mga ganyang simpleng code lang naiintindihan ko yung looping. Pero kapag nested loops na, hirap na ko. Kapag nakita ko yung solution, parang naiintindihan ko naman yung nangyayari. Pero kapag ako na ang gagawa ng program, waley na finish na 😅 :sleep:

Ayoko aralin yung mga susunod na parts ng tutorial kasi alam kong mahihirapan din ako don kung hindi ko mauunawaan talaga yung nested looping.🤪
 
always keep in mind. Outside loop will not continue if inside loop has not met its condition yet.

example outside loop 3 repitions, inside loop has 2 repitions

1. outside, inside inside
2. outside, inside, inside
3. outside, inside inside

end of loop, assuming inside loop statements met conditions or ends in a never ending cycle
 
nested loop is a looping consists of 2 or more loops. it can be a mix of different loops like while, for and foreach. Child loops cannot be executed once the statement from the mother loop is not met. All of the given number of loops given to child loop is executed before the next loop from the mother loop is executed.
 
na ka pag c++ ka ba? atleast nahasa yung understanding mo looping { } each loop most may ganito, start end.. or gamit ka ng ide atleast guide.
 
Hi guys! Inaaral ko po yung Python. Actually, sinubukan ko aralin yung JavaScript at C# noon pero huminto din ako dahil nahirapan ako maunawaan talaga yung nested looping. Tapos nahinto na naman ako. May work ako sa SEO company, pero yung ginagawa ko ay pakiramdam ko repeated tasks lang. Cool naman boss ko at mabait kaya relax ang work. Pero gusto ko talaga matutuhan yung programming kasi gusto ko makagawa ng program o web apps. Kaya sinimulan ko aralin ngayon yung Python kasi sabi madali daw siya sa lahat. Naiintindihan ko naman yung variables, if/else, conditional operator, at yung for and while loops kung isang loop lang. I mean

Python:
numbers = [8, 3, 5, 12, 21]

count = 0

for number in numbers:

    if number % 2 == 0:

        print(number)

        count += 1

if count > 1:

    print(f"You have {count} even numbers")

else:

    print(f"You have {count} even number")

Pag mga ganyang simpleng code lang naiintindihan ko yung looping. Pero kapag nested loops na, hirap na ko. Kapag nakita ko yung solution, parang naiintindihan ko naman yung nangyayari. Pero kapag ako na ang gagawa ng program, waley na finish na 😅 :sleep:

Ayoko aralin yung mga susunod na parts ng tutorial kasi alam kong mahihirapan din ako don kung hindi ko mauunawaan talaga yung nested looping.🤪

AVOID NESTED LOOPS IF POSSIBLE.

There will be cases where you might really need it. If you think you need one, I suggest to think again. Search online for possible alternatives.

Prefer declarative programming or properly decomposed pure functions.

The simple reason why you want to avoid nested loops is they can get confusing for other devs to read. If you think it's difficult for you to read your code, it's probably more difficult to read your work too.
 
Also I don't think Python is the easiest programming language to use. If you are used to C-style programming, Python may look foreign to you. Same as Ruby.

If you are Java dev, JavaScript might be an abomimation to you. Nothing is easy. My father used to tell me, "Madali kapag alam mo. Mahirap kapag hindi mo alam".
 
AVOID NESTED LOOPS IF POSSIBLE.

There will be cases where you might really need it. If you think you need one, I suggest to think again. Search online for possible alternatives.

Prefer declarative programming or properly decomposed pure functions.

The simple reason why you want to avoid nested loops is they can get confusing for other devs to read. If you think it's difficult for you to read your code, it's probably more difficult to read your work too.
Agree use functions() para neat yung coding Lalo pag sa field ka team kau sa project. Magpupull ka sa repository nyo sasalahin pa yan, Kala mo pinakamahirap mag code, mas madugo yung documentation.
 
Not really a fan of imperative style programming; loops within loops, nested if-else and prone to side effects. There's always a first time sa lahat ng bagay, kung ngayon pa lang aatras ka na dahil nahihirapan ka na sa fundamentals then programming is not for you bro. Proceed ka sa next tutorial mo, then you will know na may tinatawag tayong HIGHER ORDER FUNCTIONS ex. map, filter, reduce..etc. Sigurado ako magugustuhan mo yun kaysa sa loop, at maiintindihan mo kung bakit may Loop sa programming.
 
mahirap talaga unawain sa umpisa. Practice is the key. Pag ginagawa mo ng paulit ulit mas madadalian ka in the long run.
 
I think it will really help if you think nested looping as comparable to that of order of operations in basic arithmetic. By default, basic order of operations is Multiplication->Division->Addition->Subtraction. Say, you have this very simple equation:

Code:
x=1+4-5%4*2

If you are not going to consider the order of operations but rather compute in a left to right manner, what will you get?

In nested loops, innermost loop is computed first then the next until you hit the outermost loop. And for each iterations, the results are stored/manipulated along the way.
 
Basta practice lng dahil beneficiary yan for all languages ma encountered mo. Specially yung OOP nahirapan ako sa inheritance
 
Status
Not open for further replies.

Similar threads

Back
Top