Teen Programmers Unite  
 

 

Return to forum top

Python for loop problem

Posted by Linux_Penguin [send private reply] at March 17, 2002, 08:47:40 PM

Hi all, I haven't been in the halls of TPU in a long time. I am having trouble understanding some stuff with the for loops in Python... the book I am reading 'Learning Python' by O'Reilly press has a very confusing description of the for loop. Can anyone give a more uderstandable explanation?

Posted by PavalDaniel [send private reply] at March 18, 2002, 12:18:12 PM

eg: for (k = 1; k <= 100; k++)
cout<<k<<" ";
This for loop displays the natural numbers betwen 1 and 100.

What I did first is to initialize the variable "k" with 1.
Then I told the copiler to loop while k <= 100.
Each loop "k" is incremented (k = k + 1 or k++) so that "k" will be 100 sometime.

You can have more conditions and the incrementation part in the parantheses can miss.

Search the web for tutorials (there are a lot of useful ones!)

Posted by gian [send private reply] at March 18, 2002, 01:56:46 PM

Ummm.... that's not python, PavalDaniel.

Linux_Penguin: Come onto #tpu IRC channel (See instructions on front page). Someone there should be able to help you.

Posted by PavalDaniel [send private reply] at March 18, 2002, 02:30:01 PM

Oh!...I thought Pithon was the author's name...Sorry!

Posted by Linux_Penguin [send private reply] at March 19, 2002, 08:45:43 PM

Thanks for the help, I did check out the IRC channel and got some help.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.