While Loops

Main Points:

  • A loop is a part of a program that repeats itself. 
  • There are different types of loops, in this lesson we will just focus on the while loop.
  • The while loop tests a condition and if that condition is true it iterates. 
  • Format:
    while(condition){
    do this;
    }
  • There can be many reasons you would want to use a loop in your program. Most likely you will need a counter to track how many times the loop executes. You can either increment or decrement this value.
  • To increment a variable (number):
    number++;
  • To decrement a variable:
    number–;

View the Code!