LinkedIn principal author Doug Winnie explains how you can run sections of code over and over again using a loop. Two simple types of loops include the while loop, where a conditional test is evaluated and the code inside the loop runs for as long as the condition is true. The other type is the do while loop, where the condition is tested after the loop runs at least once.
- View Offline
- 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 chance that the loop could never run,…
Join Doug Winnie as he explains the principles of programming and helps you connect to core concepts by exploring three ways that programmers perform their jobs. Doug starts by sharing the history of coding and then dives into functions, values, variables, and parameters used to define actions. He covers capturing input from users, creating conditional tests, using loops with arrays, and object-oriented programming basics. He also takes you beyond programming, into processes like debugging, refactoring, and building iteratively.
- Working with values and variables
- Breaking down tasks
- Customizing functions and parameters
- Building conditional tests
- Creating and changing arrays
- Working with objects and classes
- Debugging and refactoring code
- Going beyond the code as a programmer