for examplesuppose numberlist is [ - - you want to process listso that suggests for-each loopfor num in numberlistbut for-each loop runs the same code body for each element of the listand we only want print(numfor some of them that seems like major obstaclebut think closer at what needs to happen concretely as humanwho has eyes of amazing capacityyou are drawn immediately to the actual correct numbers and but clearly computer doing this systematically will have to check every number in factthere is consistent action requiredevery number must be tested to see if it should be printed this suggests an if statementwith the condition num try loading into idle and running the example program onlypositive pywhose code is shown below it ends with line testing the functiondef printallpositive(numberlist)'''print only the positive numbers in numberlist ''for num in numberlistif num print(numprintallpositive([ - - ]this idea of nesting if statements enormously expands the possibilities with loops now different things can be done at different times in loopsas long as there is consistent test to allow choice between the alternatives shortlywhile loops will also be introducedand you will see if statements nested inside of themtoo the rest of this section deals with graphical examples run example program bounce py it has red ball moving and bouncing obliquely off the edges if you watch several timesyou should see that it starts from random locations also you can repeat the program from the shell prompt after you have run the script for instanceright after running the programtry in the shell bounceball(- the parameters give the amount the shape moves in each animation step you can try other values in the shellpreferably with magnitudes less than for the remainder of the description of this exampleread the extracted text pieces the animations before this were totally scriptedsaying exactly how many moves in which directionbut in this case the direction of motion changes with every bounce the program has graphic object shape and the central animation step is shape move(dxdybut in this casedx and dy have to change when the ball gets to boundary for instanceimagine the ball getting to the left side as it is moving to the left and up the bounce obviously alters the horizontal part of the motionin fact reversing itbut the ball would still continue up the reversal of the horizontal part of the motion means that the horizontal shift changes direction and therefore its signdx -dx but dy does not need to change this switch does not happen at each animation stepbut only when the ball reaches the edge of the window it happens only some of the time suggesting an if statement still the condition must be determined suppose the center of the ball has coordinates (xywhen reaches some particular coordinatecall it xlowthe ball should bounce more on flow of control