While-else is used to create loops, programming, java, software, PHP, C programming, programming languages, Alpha Codist, Perl, XML program, UNIX
While-else is used to create loops. When you want to run a code multiple times or run a piece of code for a long time you will need to use a loop and this is where "While loop" does the job. Bellow, there is given a short example where while is used to print a sentence (Follow Alpha Codist on Facebook, Instagram, Twitter.) multiple (4) times. And the liked variable was used to break the code. 1 is added with liked every single time the loop runs and when it goes from 0 to 3 the code stays true and the loop runs but when liked gets equal to the loop breaks and the sentence in else is printed.
Example:
While loop |
love_programing = True
liked = 0
while love_programing and liked <= 3:
print("Follow Alpha Codist on Facebook, Instagram, Twitter.")
liked += 1
else:
print("I followed Alpha Codists all social pages.")
COMMENTS