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 లో చాలా digit ప్రశ్నలు ఈ రెండు 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.