top of page

While and For Loops

Loops allow programs to do the same piece over and over again with slight changes until they want it to stop. When making a loop you want to answer 3 questions:

What do you want to repeat? What do you want to change each time? How long should we repeat?

A while loop seems very similar to an if statement, with a boolean expressions and a piece of code that it runs if true. They are similar but a while loop has a special condition that means it jumps back to the top of the loop each time it reaches the end to check if the boolean statement is still true. If it is still true it runs the loop again, if it isn't it carries on. For loops are similar to While loops on the surface, the main difference is that all of the conditions of the loop are inside the initial perens "()." For loops can also be "nested" inside other for loops. This allows you to loop two (or more) sets of conditions. For example, you could repeat an image, shape or string in both the x and y axis to make a grid (see below.) Project: Build a House.

 

A table of programming for While and For Loops.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • LinkedIn Social Icon
  • Pinterest Social Icon
  • Facebook Basic Square

© 2023 by Coming Soon

Proudly created with Wix.com

bottom of page