.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/basics/while_loops.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_basics_while_loops.py: ================= 1.9 while loops ================= .. important:: This lesson is still under development. .. GENERATED FROM PYTHON SOURCE LINES 10-13 Suppose we have a list of names of people who have ruled Pakistan with one name in it who has not been the ruler and we want to find out at which position the name of this person is located. One way to solve this problem is to use while loops. .. GENERATED FROM PYTHON SOURCE LINES 15-27 .. code-block:: default looters = ['sikandar mirza', 'ayub khan', 'yahya khan', 'zulfiqar bhutto', 'shahid afridi', 'zia-ul-haq', 'benazir', 'nawaz sharif', 'musharaf', 'zardari'] acc_id = 0 while acc_id `Interrupt execution`.) .. GENERATED FROM PYTHON SOURCE LINES 42-51 while with else .. code-block:: python while condition: do something else: do something at last .. GENERATED FROM PYTHON SOURCE LINES 53-67 .. code-block:: default looters = ['sikandar mirza', 'ayub khan', 'yahya khan', 'zulfiqar bhutto', 'shahid afridi', 'zia-ul-haq', 'benazir', 'nawaz sharif', 'musharaf', 'zardari'] acc_id = 0 while acc_id` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: while_loops.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_