Lesson 11 of 34

while এবং do-while Loops

8 min 25 XP

Loop কতবার চলবে আগে থেকে জানা না থাকলে while ব্যবহার করুন। Condition false হওয়া পর্যন্ত এটি চলে। Condition বদলাতে ভুলে গেলে loop কখনো শেষ হবে না!

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

do-while শেষে condition যাচাই করে, তাই body অন্তত একবার চলবেই।

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

n % 10 শেষ অঙ্ক দেয় আর n / 10 সেটি সরিয়ে দেয়। Interview-এর বেশিরভাগ অঙ্কের প্রশ্ন এই দুই কৌশলেই মেটে।

Challenge

+25 XP

একটি সংখ্যা পড়ে তার অঙ্কগুলোর যোগফল print করুন। Input: 4721 → Output: 14

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.