Break statement ka use top level loop se bahar aane ke liye hota hai, top level loop se bahar aana mtlb us loop ka execution rook dena , even if apki condition true bhi hai fir bhi agar break statement laga hai to apko us loop se bahar aana padega.
Aayiye ise example ki madad se aur clear banate hai.......
Examples:
-------------------------------------------------------------------------------
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
Output:
apple banana
# basically hm yaha fruit naam ki ek list ke element print kara rhe hai, lekin hmne
yaha condition di hai ki jaise hi hm banana pahuchenge to loop ko break kr dena hai,
aur loop ke bahar aa jana hai, isliye ap dekh skte hai ki sirf apple aur banana hi
print hue hai chreey print nhi hua hai.
-----------------------------------------------------------------------------------
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
break
print(x)
Output:
apple#ye case bhi upar jaisa hi hai, pr yaha print statement ka khel hai agar ap dhyan sedekhe to, yaha print statement baad mai laga hai isliye sirf apple bas print hua hai.---------------------------------------------------------------------------------i=0 while(i<=10): print(i) if i ==6: break i=i+1
Output:0 1 2 3 4 5 6---------------------------------------------------------------------------------CONTINUE STATEMENTContinue statement ka use current iteration ko skip krne ke liye hota hai.Examples:------------------------------------------------------fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x)Output:apple cherry# Ap dekh skte hai ki banana ko hmne skip kr diya hai, aur sirf apple or cherry print hua hai to aisa isliye hua hai kyoki hmne banana mai continue statement laga diya hai.#Hm yaha bol rahe hai ki jaise hi banana pahuche use skip kr dena.---------------------------------------------------------------------------------------Program to print the number between 1 to 10 which is notdivisible by either 3 or 5for x in range(10): if x %3==0 or x %5==0: continue else: print(x)
Output:1 2 4 7 8---------------------------------------------------------------------------------PASS STATEMENTPass statement kuch nhi krta hai, ji ha pass statement kuch bhi nhi krta hai, Iska use tb hota hai jb program ko koi bhiaction perform na krna ho.In simple words hm python mai koi bhi statement ko khali nhichhod skte ,is situation mai hm waha pass statement ka usekrte hai.Example:----------------------------------------------------------Program to print the even numberfor x in range(10): if x%2!=0: pass else: print(x)
Output:0 2 4 6 8----------------------------------------------------------------------------------
Comments
Post a Comment