Repetition
What is the purpose of iterative structures in programming?
Apuntes
Repetition Chapter 6 2 Topics We will Cover In This Chapter • Iterative Structures • While Loop • For Loop 3 Iterative Structures Recall the three types of structures in Computer Programming: • Sequential • Decision (If Statements) • Iterative Iterative Structures involve repetition of programming statements as long as some given condition evaluates to true. 4 While Loop Python has two main Iterative Structures: • While Statement – Repeats for a given condition, usually repeats an indeterminate number of times. • For Statement – Used to repeat a specific number of times, OR to iterate over an array (or list). 5 While Statement While Structure • Tests if a given condition is true • If yes, executes its body AND tests the condition AGAIN. • If no, “halts” the repetition of the while loop and continues to the next line of code that comes after the loop.. Syntactical Description of Python’s While Loop: while condition : statement 1 statement 2 statement 3 ... .. First statement outside the while loop. Cond Body of loop True False 6 While Loop Output counter = 0 total = int ( input ( "How large should" "your rectangle be? " )) while ( counter < total ): print ...
Estudia con juegos interactivos
Sube tus apuntes y genera flashcards, examenes y mas con IA
Empezar gratis