DEV Community

Hasan Mahmud Rhidoy
Hasan Mahmud Rhidoy

Posted on

Understanding the Usage of break and continue Keywords

break এবং continue কীওয়ার্ডের ব্যবহার দেখানোর জন্য আমরা একটি উদাহরণ ব্যবহার করব যা আপনার বাস্তব জীবনের প্রবলেমের সাথে মিল রেখে তৈরি করেছি।

Break

আপনি একটি লটারির টিকিট কিনেছেন এবং একটি নির্দিষ্ট নম্বর পাওয়ার সাথে সাথে খেলা থামাতে হবে। যদি আপনি ৭ নম্বরটি পান, তাহলে খেলা থামবে।

tickets = [1, 3, 5, 7, 9, 11, 13]
lucky_number = 7
found = False

for ticket in tickets:
    if ticket == lucky_number:
        found = True
        break  # লুপ থেকে বেরিয়ে যাবেন কারণ লাকি নম্বর পাওয়া গেছে।
    print(f"Checked ticket: {ticket}")

if found:
    print("Lucky number found!")
else:
    print("Lucky number not found.")
Enter fullscreen mode Exit fullscreen mode

Continue

একটি পরীক্ষার খাতা মূল্যায়ন করছেন যেখানে প্রতিটি ছাত্রের নম্বর যাচাই করতে হবে। যদি কোনো ছাত্রের নম্বর ৩৩-এর কম হয়, তাহলে তাকে ফেল হিসেবে চিহ্নিত করে পরবর্তী ছাত্রের নম্বর দেখতে হবে, কিন্তু কোনো গ্রেড যোগ করা হবে না।

scores = [45, 67, 29, 75, 33, 48, 55]
passing_score = 33
total_score = 0
num_passed = 0

for score in scores:
    if score < passing_score:
        print(f"Score {score} is below passing mark.")
        continue  # এই ছাত্রের স্কোর যোগ না করে পরবর্তী ছাত্রের কাছে যাবেন।
    total_score += score
    num_passed += 1

if num_passed > 0:
    average_score = total_score / num_passed
else:
    average_score = 0

print("Average Score of Passed Students:", average_score)
Enter fullscreen mode Exit fullscreen mode

এই উদাহরণগুলি বাস্তব জীবনের বিভিন্ন সমস্যায় break এবং continue কীওয়ার্ডের ব্যাবহার দেখায়। এইভাবে আপনি বিভিন্ন সমস্যায় এই দুটি কীওয়ার্ড কীভাবে ব্যবহার করবেন তা বুঝতে পারেন।

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay