while


while-ல் உள்ள condition True ஆக இருக்கும் வரை while-க்கு கீழ் உள்ள அனைத்தும் run ஆகிக் கொண்டே இருக்கும். condition தவறாகும் போது  while loop செயல்படாது.

While Loop Syntax Python

while condition:
    Body of while

While Loop Example in Python


count = 0
while count < 10:
    print(count)
    count += 1  

Output

0
1
2
3
4
5
6
7
8
9


Example 2)
உதாரணம் 3:
var = 10
while var > 0:
print (‘Current variable value :’, var)
var = var -1
print(“Good bye”)

var என்ற variable-ல் 10 என்பது store செய்யப்படுகிறது.var என்ற variable-ன் மதிப்பானது while loop-ல் 0-வை விட பெரியதா என்று check செய்து கீழே உள்ள statement ஆனது செயல்படுத்தபடும்.      var என்ற variable-ன் மதிப்பானது ஒன்றன் கீழ் ஒன்றாக குறைக்கப்பட்டு வரும் 0 என்றதும் while loop ஆனது முற்றிலுமாக முடிந்து “good bye” என்று display செய்யப்படும்.இதன் வெளிப்பாட்டைபடத்தில் காணலாம்.

No comments:

Post a Comment