Does python have foreach loops? I don't see any
mention of them in the docs. Am I going to have to
use Perl (gasp!) if I want my beloved foreach loop?
Its called a for loop in Python...
Or is there some extra magic in the Perl version that I'm missing?
Alan G.
I was thinking more along the lines of this:
A C++ for loop:
This is exactly NOT a foreach loop, its a vanilla for loop.
#include iostream
using std::cout;
int main() {
for (int i = 0; i 10; i++) {
cout i \n;
}
for i in range(10): print i
Alan G.
Does python have foreach loops? I don't see any
mention of them in the docs. Am I going to have to
use Perl (gasp!) if I want my beloved foreach loop?
-Chris
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Does python have foreach loops? I don't see any mention of them in the
docs. Am I going to have to use Perl (gasp!) if I want my beloved
foreach loop?
Can you show an example of a Perl foreach loop? Perhaps someone can help
translate it into idiomatic Python.
Good luck!
Danny Yoo wrote:
Does python have foreach loops? I don't see any mention of them in the
docs. Am I going to have to use Perl (gasp!) if I want my beloved
foreach loop?
Can you show an example of a Perl foreach loop? Perhaps someone can help
translate it into idiomatic Python.
Christopher Spears wrote:
Hmmm...Perl is probably a bad example. My apologies.
I was thinking more along the lines of this:
A C++ for loop:
#include iostream
using std::cout;
int main() {
for (int i = 0; i 10; i++) {
cout i \n;
}
Christopher Spears wrote:
Hmmm...Perl is probably a bad example. My apologies.
I was thinking more along the lines of this:
A C++ for loop:
#include iostream
using std::cout;
int main() {
for (int i = 0; i 10; i++) {
cout i \n;
}