Class 04
Class 04 : For Loops, While Loops
Key Differences
Control Flow:
“Forloops” are more structured and provide a clear mechanism for initialization, condition checking, and iteration.“Whileloops” give us more flexibility, allowing us to control the loop more directly.
Structure:
“For loops” have an explicit initialization, condition, and iteration expression within the loop header.
“While loops” have just the condition at the beginning. We need to manually handle initialization and iteration within the loop body.
Created a pattern by making something with a lot of repetition.Re-writed it using a loop
Pattern 1
I created a checkerboard grid of 100 cells by using % Modulo
I created something loop without using a for loop or a while loop by using “Function“.
Pattern 2
Summary
“Forloops” are commonly used when we know the number of iterations in advance or we want to iterate over a range of values.“Whileloops” are used when we're not sure how many iterations are needed and want to continue looping until a certain condition is met.