Computer Skills II 2024-2025 PDF
Document Details
Uploaded by Deleted User
2024
Mela G. Abdul-Haleem
Tags
Summary
These lecture notes cover iterative control structures, including while and for loops, in Python. The examples given pertain to basic looping practices and show use of the range() function in for loops.
Full Transcript
Second Class/Biotechnology 2024-2025 Theoretical and Practical Lecture Eight Loop & Body of Loop By Lect. Mela G. Abdul-Haleem Lec.8 and Lab.8 Computer Skills II Mela G. Abdul-Haleem Iterative control structures:...
Second Class/Biotechnology 2024-2025 Theoretical and Practical Lecture Eight Loop & Body of Loop By Lect. Mela G. Abdul-Haleem Lec.8 and Lab.8 Computer Skills II Mela G. Abdul-Haleem Iterative control structures: In Python, an iterative statement, or loop, is a fundamental programming concept that allows you to repeat a block of code multiple times. Loops are used when you need to perform repetitive tasks without writing redundant code. Iterative statements or loop statements allow us to execute a block of statements as long as the condition is true. Types of iterative (loop) statements: while loops for loops 1- The while Loop A while statement is an iterative control statement that repeatedly executes a set of statements as long as a condition is true. Syntax while condition: code block (statements) to execute A condition is a boolean expression that is checked before each iteration. The loop continues as long as the condition evaluates to True. Example 1: Basic while loop c=1 Output: while c < 3: 1 2 print(c) c=c+1 Tracing i) While c