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 അത് നീക്കം ചെയ്യുന്നു. Interviews-ലെ മിക്ക അക്ക ചോദ്യങ്ങളും ഈ രണ്ട് tricks കൊണ്ട് പരിഹരിക്കാം.

Challenge

+25 XP

ഒരു സംഖ്യ വായിച്ച് അതിന്റെ അക്കങ്ങളുടെ തുക print ചെയ്യൂ. Input: 4721 → Output: 14

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