Skip to playerSkip to main contentSkip to footer
  • 5/20/2025
An infinite loop in Python is a sequence of code that repeats indefinitely because it lacks a functional exit condition. This can happen intentionally for continuous processes or unintentionally due to programming errors. Infinite loops can be created using while or for loops.
For while loops, an infinite loop occurs when the condition is always true:

Category

📚
Learning
Transcript
00:00In this lecture, I will teach you while loop.
00:02While loop is called infinite loop.
00:06Infinite loop is called infinite loop.
00:08It is called infinite loop.
00:10It is called run when your condition is true.
00:13While loop is called if loop.
00:15The syntax is called if loop.
00:17The syntax is called if loop.
00:19And depending on the condition,
00:21the block of code is called execute.
00:23This is called if loop.
00:25If you modify it,
00:27you can use while loop.
00:30While loop,
00:32under the block of code,
00:35let's say,
00:37block of code,
00:39basically,
00:41when the condition is true.
00:43I run,
00:47because condition is true.
00:53This condition is true.
00:55It will keep on running.
00:57It will keep on running.
00:58It will keep on running.
00:59It will keep on running.
01:01It will keep on running.
01:02It will keep on running.
01:03It will keep on running.
01:04Jب تک یہ condition false نہیں ہوتی.
01:05یہاں تک آپ کا program crash ہو جائے گا,
01:06while loop stop نہیں ہوگا.
01:07کیوں?
01:08کیونکہ یہ infinite loop ہے.
01:09اور اس کو کسی نہ کسی طریقے سے
01:11close کرنے کا
01:12ہم نے mechanism device کرنا ہوتا ہے.
01:14اب آپ نے دیکھا کہ
01:16ہمارا for loop جو ہے
01:17وہ run کر رہا ہے.
01:18Right?
01:19اچھا.
01:20اب ذرا میں اس کو close کرتا ہوں.
01:21اور اس condition کو
01:22میں کسی variable کو بھی تو
01:23assign کر سکتا ہوں.
01:24میں کہتا ہوں.
01:25let's say x is equal to true.
01:27x replace کر دیتا ہوں.
01:29basically میں ایک ہی بات کر رہا ہوں.
01:31ایسا ہی ہے نا.
01:32میں اس کو run کرتا ہوں.
01:33you will see the same result.
01:34I run because condition is true.
01:36اب ذرا میں
01:38اس کو
01:39change بھی تو کر سکتا ہوں.
01:41مثال کے طور پر یہ true
01:42ہم using comparison operator بھی
01:44تو achieve کر سکتے ہیں.
01:45مثال کے طور پر
01:46میں کہتا ہوں.
01:47let's say 2 is greater than 1.
01:49یہ کیا condition ہے.
01:51یہ بھی تو true ہی ہے نا.
01:52اگر میں اس کے اوپر
01:53bool کا function call کروں.
01:55کہوں bool
01:56check کرو operator کو
01:57اور مجھے print کر کے دو اس کا result.
01:59تو دیکھتے ہیں کیا تھا.
02:01یہ دیکھئے.
02:02میں اس کو execute کرتا ہوں.
02:03اس کو remove کر دیتے ہیں
02:04for the moment.
02:05ٹھیک ہے.
02:06execute کرتا ہوں.
02:07bool to one is true.
02:08تو اس کا مطلب یہ ہے
02:09کہ اگر میں
02:10یہاں پہ simple
02:11two is equal to one
02:12replace کر دوں.
02:13تو python
02:14automatically اس کے اوپر
02:15bool کا function run کر کے
02:16check کرے گا
02:17کہ condition true
02:18یا false ہے.
02:19کیونکہ یہ condition true ہے.
02:20تو again we will see the same result.
02:21یہ دیکھئے.
02:22run کرتا ہوں.
02:23and then i run
02:24because condition is true.
02:25this is cool.
02:26right?
02:27اب اس کو مزید
02:28interesting بناتا ہے.
02:29مثال کے طور پہ
02:30میں یہ بھی تو کر سکتا ہوں.
02:31کہ میں اس x اور y کو remove کرتا ہوں.
02:33میں کہتا ہوں x is equal to two
02:35and y is equal to one.
02:37یہ بھی تو کر سکتا ہوں
02:38میں.
02:39اور یہاں پہ simple بجائے
02:40two اور one لکھنے کے hardcoded
02:41پہ variable replace کر دیتا ہوں.
02:42اور اس کو execute کرتا ہوں.
02:43and you will see the same result.
02:45because میں نے کوئی چیز
02:46change نہیں کی.
02:47ایسا ہی ہے نا.
02:48یہ دیکھے execute کرتا ہوں.
02:49and you see the same result.
02:50i run because x and y is true.
02:54okay.
02:55تو چلیے.
02:56تھوڑا سا code کو مزید
02:57versatile بناتے ہیں.
02:58کہ میں f string use کر کے
03:00اس condition کو evaluate کرتا ہوں.
03:01تاکہ مجھے پتا چلے
03:03کہ یہ basically under the hood
03:04actually ہو کیا رہا ہے.
03:05ٹھیک ہے.
03:06میں اس کو close کرتا ہوں.
03:07اور simple یہاں پہ f string
03:08use کرتا ہوں.
03:09میں کہتا ہوں.
03:10یار f string بات سنو.
03:11یہ جو value میں نے دیا ہے
03:12x اور y.
03:13اس کو ذرا لگاؤ.
03:14x میں کہتا ہوں greater than y.
03:17ٹھیک ہے.
03:18اور اس کے بعد بولتا ہوں
03:20returns.
03:21ٹھیک ہے.
03:22اور اب میں simple bool کا function
03:24call کر دیتا ہوں.
03:25bool.
03:26کیا کرو bool.
03:27بھولنے کا کیا کرو.
03:28میں نے کہا.
03:29یار تم اس طرح کرو.
03:30یہ x اور y کو evaluate تو کرو.
03:31ہر loop کے اوپر.
03:32دیکھو یہ کیا return کرتی ہے.
03:33ٹھیک ہے.
03:34then مجھے result show کرو.
03:35اب میں اس کو execute کرتا ہوں.
03:36and you will see.
03:37وہ کہہ رہا ہے.
03:38two greater than one
03:40returns true.
03:41تو اس لئے یہ execute ہو رہا ہے.
03:43اب میں اس کو مزید sophisticated بناتا ہوں.
03:45میں کہتا ہوں.
03:46i ran because i run because x is greater than and bla bla bla.
03:58اب دیکھئے.
03:59وہ کہتا ہے.
04:00i run because.
04:01اور یہ code execute.
04:03وہ کہتا ہے.
04:04i run because.
04:05اور یہ code execute ہو رہا ہے.
04:06یہ روک نہیں رہا.
04:07i run because.
04:08two is greater than one.
04:09two is greater than one.
04:10it's always will be two is greater than one.
04:12اب میرے پاس کوئی.
04:14کیا ایسا mechanism ہے.
04:15کہ میں.
04:16اس condition کو کسی طریقے سے change کرا سکوں.
04:18نہیں ہے نا کوئی mechanism.
04:20تو ہم.
04:21basically ایک mechanism device کر سکتے ہیں.
04:23میں اس کو close کرتا ہوں.
04:24میں کہتا ہوں.
04:25یار.
04:26کسی نہ کسی طریقے سے.
04:27اگر یہ one.
04:28کو میں two کر سکوں نا.
04:29one.
04:30کیونکہ.
04:31two is greater than one.
04:32اگر کسی نہ کسی طریقے سے.
04:33یہاں پہ.
04:34ایسا میں فارمولہ لگا ہوں.
04:36کہ y کے اندر ایک add ہو جائے.
04:38تو next time جب وہ اوپر جائے گا.
04:40تو y کی value دو پکڑ کے جائے گا.
04:42جب دو پکڑ کے جائے گا.
04:43تو.
04:44of course.
04:45two.
04:46will not be greater than two.
04:47condition false ہو گئی.
04:48اور یہ برران نہیں ہوگا.
04:49چلیئے.
04:50میں اس طرح کرتا ہوں.
04:51then میں کہتا ہوں.
04:52یار.
04:53y is equal to.
04:54تو کیوں نہ y کے اندر ایک add کر دیا جائے.
04:56ٹھیک ہے.
04:57اور اس کو execute کرتے ہیں.
04:59and then it ran only once.
05:01کیوں.
05:02کیونکہ next time.
05:03جب وہ آیا.
05:04اور میں نے کہا.
05:05print کرو y کی value.
05:06ٹھیک ہے.
05:08میں نے کہا.
05:09print کرو y کی value.
05:10تو you will see.
05:11تو y کی value basically 2 ہے.
05:13اب اس case میں.
05:14جہاں پہ اگر آپ 2 replace کریں.
05:16تو 2 is not greater than 2.
05:18تو condition false ہو گئی.
05:19تو وہ run نہیں ہوا.
05:20makes sense.
05:21اب ذرا آپ نے خور کرنا ہے.
05:22میں اس طرح کرتا ہوں.
05:23اس کو 10 کر دیتا ہوں.
05:24اب اس کو execute کرتا ہوں.
05:26and you see.
05:27i run because 10 is greater than 1.
05:29لیکن next time آپ دیکھیں.
05:30y 2 ہوا.
05:32لیکن پھر بھی condition true رہی.
05:33کیونکہ 10 still greater than 2.
05:353 ہوا.
05:3610 still greater than 3.
05:377 ہوا.
05:3810 still greater than 7.
05:409 ہوا.
05:4110 still greater than 9.
05:42تو یہ run ہوا.
05:43however.
05:44جب y کی value 10 ہوئی.
05:45تو یہ condition false ہو گئی.
05:47loop ہمارا رو گیا.
05:48isn't it interesting.
05:49it's very interesting.
05:51اب ذرا آپ نے دیکھنا ہے.
05:52کہ اس condition کو basically میں
05:54augmented condition میں
05:55ایسے لکھ سکتا ہوں.
05:56compact form کے اندر.
05:57تو you will get the same result basically.
06:00i run because
06:01yes condition is true.
06:03تو y کی value جو ہے.
06:04آپ directly دیکھ رہے ہیں.
06:05کیا change ہو رہی ہے.
06:07اب ہم جس طرح if کے ساتھ
06:09else statement use کرتے تھے.
06:11ہم while کے ساتھ بھی
06:12else statement use کر سکتے ہیں.
06:15interesting enough.
06:17لیکن
06:18یہ while تب execute ہوگی.
06:20sorry
06:21else تب execute
06:22while false ہوگا.
06:23تو میں اس طرح کرتا ہوں.
06:24else کی value ڈالتا ہوں.
06:25میں کہتا ہوں else.
06:26تو else print کرو
06:27یا.
06:28تم کب execute ہوگی.
06:29ٹھیک ہے.
06:30تم کب execute ہوگی.
06:32تم condition.
06:33تو میں یہاں پہ کہتا ہوں.
06:35execute.
06:36and you see
06:38وہ کہہ رہا ہے.
06:39i run because
06:4010 is greater than 10
06:41return false.
06:42کیونکہ
06:4310 greater than 10
06:44if value نے
06:46basically false return کیا
06:47تب ہی else execute ہوا.
06:49otherwise
06:50کیونکہ
06:51یہ true
06:52جب تک یہ true return کر رہا تھا.
06:54جب تک یہ
06:55true value return ہو رہی تھی.
06:56تو یہ block of code execute ہو رہا تھا.
06:58یہ والا.
06:59جب false return کیا
07:01condition change ہوئی.
07:02تو یہ
07:03else والا code return ہوا.
07:04else والا code return ہوا.
07:05run ہوا.
07:06right.
07:07okay.
07:08excellent.
07:09تو یہاں پہ اس lecture کو stop کرتے ہیں.
07:11we will continue from here.
07:12we will continue from here.

Recommended