5.4 For Loops vs. While Loops

For Loops vs. While Loops

For loops and While loops can seem almost identical at first, and even though they are similar, they have their own strengths and purposes which make them good for different scenarios. But for now, just know that a while loop does something again and again until a condition is no longer satisfied, and a for loop does something a set number of times, usually the length of a list.


Add all the Way

Take a number from the user and add every number up from 1 to that number. You can use a for or while loop

Next Section

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.