loops/quickref.tex
changeset 324 4054b1a6392d
parent 285 7c4855fb8e5f
equal deleted inserted replaced
323:e675f9208b91 324:4054b1a6392d
     1 Creating a linear array:\\
     1 \textbf{loops}
     2 {\ex \lstinline|    x = linspace(0, 2*pi, 50)|}
       
     3 
     2 
     4 Plotting two variables:\\
     3 To iterate over a sequence: \lstinline|for i in sequence:|\\
     5 {\ex \lstinline|    plot(x, sin(x))|}
     4 \texttt{i} is the looping variable. 
     6 
     5 
     7 Plotting two lists of equal length x, y:\\
     6 To iterate while a condition is true: \lstinline|while condition:|
     8 {\ex \lstinline|    plot(x, y)|}
     7 
       
     8 Blocks in python are indented. To end block return to the previous
       
     9 indentation. 
       
    10 
       
    11 To break out of the innermost loop: \lstinline|break|
       
    12 
       
    13 To skip to end of current iteration: \lstinline|continue|
       
    14 
       
    15 \lstinline|pass| is just a syntactic filler. 
       
    16