A for loop is a control flow statement that allows you to repeatedly execute a block of code based on a specified number of iterations. It consists of an initialization, condition, and increment/decrement.
Think of a for loop as a conveyor belt in a factory. The initialization sets the starting point, the condition checks if there are still items on the belt, and the increment/decrement moves the belt forward or backward.
While Loop: A while loop is another type of control flow statement that repeatedly executes a block of code as long as a given condition is true.
Nested Loop: A nested loop is when one loop is placed inside another loop. This allows for more complex iterations and patterns.
Index Variable: An index variable is used in loops to keep track of the current iteration or position within the loop. It can be incremented or decremented to control the flow of execution.
Study guides for the entire semester
200k practice questions
Glossary of 50k key terms - memorize important vocab
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.