<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Loops_with_for_and_while</id>
	<title>Loops with for and while - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Loops_with_for_and_while"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Loops_with_for_and_while&amp;action=history"/>
	<updated>2026-05-14T01:23:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Loops_with_for_and_while&amp;diff=9207&amp;oldid=prev</id>
		<title>Kristian Rother at 20:09, 5 February 2013</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Loops_with_for_and_while&amp;diff=9207&amp;oldid=prev"/>
		<updated>2013-02-05T20:09:39Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cat|Python Commands }}&lt;br /&gt;
{{Python Links}}&lt;br /&gt;
&lt;br /&gt;
== Unconditional loops with &amp;#039;&amp;#039;for&amp;#039;&amp;#039; ==&lt;br /&gt;
For loops require a sequence of items that is iterated over. This can be a list, a tuple, a string, a dictionary or any Python object that behaves like one of them (e.g. a file). Examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for i in range(3):&lt;br /&gt;
print i&lt;br /&gt;
&lt;br /&gt;
for char in &amp;#039;ABCD&amp;#039;:&lt;br /&gt;
print char&lt;br /&gt;
&lt;br /&gt;
for elem in [1,2,3,4]:&lt;br /&gt;
print elem&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conditional loops with &amp;#039;&amp;#039;while&amp;#039;&amp;#039; ==&lt;br /&gt;
While loops require a conditional expression at the beginning. These work in exactly the same way as in if.. elif statements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
i = 0&lt;br /&gt;
while i &amp;lt; 5:&lt;br /&gt;
print i&lt;br /&gt;
i = i + 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== When to use &amp;#039;&amp;#039;for&amp;#039;&amp;#039; ==&lt;br /&gt;
&lt;br /&gt;
* When the number of iterations is known at the beginning.&lt;br /&gt;
* Printing numbers, concatenating a list of strings.&lt;br /&gt;
* Modify all elements of a list.&lt;br /&gt;
&lt;br /&gt;
== When to use &amp;#039;&amp;#039;while&amp;#039;&amp;#039; ==&lt;br /&gt;
&lt;br /&gt;
* When there is a exit condition.&lt;br /&gt;
* When it may happen that nothing is done at all.&lt;br /&gt;
* When the number of repeats depends on user input.&lt;br /&gt;
* Searching for a particular element in a list.&lt;/div&gt;</summary>
		<author><name>Kristian Rother</name></author>
	</entry>
</feed>