Skip to main content

17.Python While Loop

PYTHON WHILE LOOP
    The while statement is one of the conditional looping or the entry controlled looping statements. while loop is used to execute a set of statements when the condition is true. The suite in a while clause will be executed continuously in a loop until the given condition is no longer satisfied.

    Since the test for exit of the loop is performed before the first instruction in the loop, based on the condition it may not execute for a single time. The variables appearing in the logical expression are initialized prior to the beginning of the while loop. This is important
since the logical expression in the while loop will be tested before the loop gets executed. 
Syntax 
while expression/condition :
    statements 
break
    The break statement is used to stop the loop even if the while condition is true.The most common use for break is when some external condition is triggered, requiring an immediate exit from a loop.Break can be used in both for loop and while loop. 
continue
    The continue statement is used to stop the current iteration, and continue with the next iteration. In other words,Whenever a continue statement in Python is initiated/encountered it re-starts a loop, skipping the following statements in the block. It could be used with both while and for loops. 
else 
    Like in if statement,the else statement is used to run a block of code once when the condition becomes false. In other words, When an else statement is used with a while statement, the else statement is executed when the expression evaluates to Boolean False. 
Program 
i = 1
while i < 26:
    print(i)
    i +=1
    if(i>96):
        break
   elif i==23:
        pass
   else:
        continue
print(i) 
Output 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
Watch the video below to know about python in detail!!

Happy Learning!!










Comments

Popular posts from this blog

Get Ethical Hacking Project #1

Thanks for your interest in our course This is a paid course, 150 rs for Indian people, 5$ for international people Instructions to get course: Indian people can get the course by paying using this UPI id   tamilhacks@ybl  (KARTHIKEYAN T) send 150 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)     The above mentioned method is most preferable. if you don't have a upi id app, install  phonepe  or  google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100 Rs for tax and other charges here )   After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that . the course is in zip format, so after downloading the file extra

Learn c++ in Tamil | Complete guide and tutorial | Beginner to Advance all concepts explained.

hi guys welcome , all the coding used in video are available here : /* hi guys welcome to learn c++ in tamil what is C++ how what software your own program schools,clg,institute.... start 1.interest 2.patience 3.fun 4.practise computer program - app - programming source code - hardware - fb running , executing machine language :  101010 assembly lang : mov h1; high lang : c , c++....java , js , python  eg :  a+b .....1001010  compiler :  human to machine              machine to human  rules :  a+b;  usage:  games, manufacturing , embedded , finance , graphics , etc...  Guide: 1.problem 2.solution - alternative 3.program  - C++ 4.compile  - turboc , ide , codeblocks , cmd 5.result   - library file - linker : #include<iostream.h>    input , output std::cout<<"welcome";   standard character out << " "; primary section : 1.statements   ;  end 2.functions   main() 3.syntax  , syntax error pra

Get Bug Bounty Course

Thanks for your interest in our course Limited Offer This is a paid course, Rs 10000 ,Rs 1000  for Indian people, 75$ 15$ for international people , 50$ 10$ for Srilankan people Instructions to get course: Indian people can get the course by paying using this UPI id  tamilhacks@ybl  send 1000 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)    The above mentioned method is most preferable. if you don't have a upi id app, install phonepe or google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100Rs for tax and other charges here ) After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that. As for international peopl