Lesson 15 of 34
Loop Patterns: கூட்டல், எண்ணுதல், வடிவங்கள்Loop Patterns: Totals, Counts and Shapes
10 min 35 XP
Pattern 1, கூட்டல் (accumulator): loop-க்கு முன் total = 0 என வைத்து, ஒவ்வொரு சுற்றிலும் கூட்டுங்கள்.
Pattern 1, the accumulator: set total = 0 before the loop and add to it in every round.
Example: edit me and press Run
Press Run to see the result here.Pattern 2, எண்ணுதல் (counter): நிபந்தனை உண்மையாகும் போது மட்டும் count-ஐ 1 கூட்டுங்கள்.
Pattern 2, the counter: add 1 to count only when a condition is true.
Example: edit me and press Run
Press Run to see the result here.Pattern 3, வடிவங்கள் (shapes): "*" * 3 என்பது "***". இதை loop-உடன் சேர்த்தால் அழகான வடிவங்கள் வரும்.
Pattern 3, shapes: "*" * 3 gives "***". Combine it with a loop to draw shapes.
Example: edit me and press Run
Press Run to see the result here.இந்த மூன்று patterns-ஐயும் புரிந்துகொண்டால், பல coding interview கேள்விகளை எளிதாகத் தீர்க்கலாம்.
Master these three patterns and many coding interview questions become easy.