You are viewing a single comment's thread from:

RE: Learn Basic Python Programming EP.3. - Logic & Loops

in #programming7 years ago

Sweet!

The way I like to think about the for loop in python is that it's actually the foreach from other languages. Since you can achieve with the while loop anything you could with the classical for loop why not shorten the foreach and call it a day!

Sort:  

I didnt quite understood what is the difference between foreach and for, I believe it can iterate other things too not just numbers.

Also keep in mind that I have like medium knowledge about python, I have not much experience with using classes and other objects , I have to learn more about those. But I will touch functions and other basic things in this tutorial.

Explaining to others is a great way of making sure you understand something, it's a good thing to do once you feel like you master something. It also helps you figure out what you don't understand that well and look over it again.

The idea is that Python doesn't have a foreach syntax like other languages, instead the for loop works like a foreach would. If you have no idea what I'm talking about don't stress it, it's just a tip for whoever is coming from another language that has the classic for loop

for (element = 0; element < list; element++)

to remember that python's for is actually a foreach

foreach element in list:
___do stuff

Coin Marketplace

STEEM 0.21
TRX 0.13
JST 0.030
BTC 66847.77
ETH 3497.61
USDT 1.00
SBD 2.89