Python - Using integer to control while loop

Introduction

Python's while loop is a more general sort of looping tool.

It's not limited to stepping across sequences, but generally requires more code to do so:

Demo

x = 4 
while x > 0: #  w  w w  .  j  a v  a 2  s  .  co m
   print('test!' * x) 
   x -= 1

Result

Related Topic