From the course: Computer Science Principles: Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use while loops
From the course: Computer Science Principles: Programming
Use while loops
- Programming allows us to repeat actions multiple times. We can used named sections of code called functions to execute lines of code whenever we need to run them. That's fine for when we need to intermittently run sections of code, but if we want to run the code over and over again, we can use loops. Loops are ways a programmer can take a section of code and have a program run them multiple times. Using a conditional, the programmer can define a limit to the number of times a loop runs. The most basic loop is a while loop. It works like this. At the top you ask a question as a conditional statement that evaluates as either true or false. If the answer to the question is true, then the code in the loop runs, and then it goes back to the top and asks the question again. If the answer to the question is ever false, then the loop stops and doesn't run again, and the program continues with code after the loop. With this type of loop, it will run for as long as it is true. But there is a…
Contents
-
-
-
-
-
(Locked)
Capture input from the user3m 31s
-
(Locked)
Manage different variable types2m 4s
-
(Locked)
Create conditional tests4m 39s
-
(Locked)
Build compound conditional tests4m 19s
-
(Locked)
Use while loops2m 11s
-
(Locked)
Use for loops3m 11s
-
(Locked)
Create arrays to store groups of values2m 28s
-
(Locked)
Use loops with arrays2m 5s
-
Changing arrays2m
-
(Locked)
-
-
-