Member-only story

Learn while loops by creating a simple pig latin generator

Crystal X
2 min readJun 18, 2023

--

Pig latin is a game that we played as children. The idea is to take the first letter of a word, move it to the last position, and add the letters ‘ay’ to it.

Making a pig latin generator is a good way to learn about while loops. In Python, a while loop is a control flow statement that allows you to repeatedly execute a block of code as long as a certain condition is true. The while loop keeps iterating until the condition becomes false.

The pig latin generator is comprised of a while loop that will continue to run indefinitely. The psuedocode for the generator is as follows:-

  1. The user will be prompted to enter a word.
  2. The while loop will continue to run as long as the word entered is not ‘quit’, and at which time a message will come up saying the program has ended and will break out of the for loop.
  3. If the word entered is not all alphabetical characters, the user will be given a message saying the word must be all letters in English, and the program will continue to the beginning of the loop.
  4. When the user enters a word in English, the first letter of the word (position 0) will be moved to the last position and the letters ‘ay’ will be added to it.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet