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.