<div dir="ltr">Although Python does lack some classic control flows notably do-while and switch-case, it offers plenty of other uniq control flows. I often use a else statement with a for loop. Python also offers list and dictionary comprehension.<div><br></div><div><a href="https://docs.python.org/3.5/tutorial/controlflow.html">https://docs.python.org/3.5/tutorial/controlflow.html</a> </div><div><a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions">https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions</a><br></div><div><br></div><div>I would also suggest that you can easily implement a do-while like such:</div><div><br></div><div>while True:</div><div>    pass # Do Stuff</div><div><br></div><div>    if condition: break # Our do statement</div><div><br></div><div><br></div><div>Switch-cases are a little tricky. Most the time a if ... elif ... else works just fine, although this is a bit limiting if you want to use a fall through condition. A neat trick that you can do with python is use a dictionary as a switch-case.</div><div><br></div><div>def foo():</div><div>   print("foo")</div><div><br></div><div>def bar():</div><div>   print("bar")</div><div><br></div><div>def baz():</div><div>   print("default baz")</div><div><br></div><div>map = {</div><div>    "Blue": foo,</div><div>    "Red": bar</div><div>}</div><div><br></div><div>map.get("Red", baz)() # bar</div><div>map.get("Yellow", baz)() # default baz</div><div><br></div><div>This has the added advantage that you can dynamically build out the dictionary map.</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">--<br>William Clemens<br>Phone: 847.485.9455<br>E-mail: <a href="mailto:wesclemens@gmail.com" target="_blank">wesclemens@gmail.com</a><br></div></div>
<br><div class="gmail_quote">On Mon, Jun 15, 2015 at 10:55 PM, Lewit, Douglas <span dir="ltr"><<a href="mailto:d-lewit@neiu.edu" target="_blank">d-lewit@neiu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><font size="4">if __name__ = "__main__":</font><div><font size="4">       etc.</font></div><div><font size="4">       etc.</font></div><div><font size="4">       etc.<br></font><div><br></div><div><font size="4">Now I get it.  Do you want to just import the methods from your .py file?  Or do you want to actually run the program directly?  Cool stuff!</font></div><div><font size="4"><br></font></div><div><font size="4">Best,</font></div><div><font size="4"><br></font></div><div><font size="4">Douglas.</font></div><div><font size="4"><br></font></div><div><font size="4">P.S.  Any thoughts on Ruby guys?  I've been messing around with it lately.  Sort of Python-like, but it actually offers more constructs than Python.  For example, Ruby has a do-while loop and Ruby offers two different ways to represent ranges, one with the upper limit included and the other with the upper limit excluded--as in Python.  But Ruby has a very "Pythonic" feel to it.</font></div></div></div>
<br>_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div>