Repeat Loop with Break in R
📖 Scenario: You are counting the number of times you toss a coin until you get heads.
🎯 Goal: Build a program that uses a repeat loop to simulate tossing a coin repeatedly and stops when it lands on heads.
📋 What You'll Learn
Create a variable
tosses to count the number of coin tossesCreate a variable
coin to store the result of each tossUse a
repeat loop to simulate tossing the coinUse
break to stop the loop when the coin lands on headsPrint the total number of tosses after the loop ends
💡 Why This Matters
🌍 Real World
Counting attempts until success is common in games, simulations, and quality testing.
💼 Career
Understanding loops and breaking conditions is essential for automating tasks and controlling program flow.
Progress0 / 4 steps