The for loop is a control flow statement that's used to iterate through a sequence of values. The while loop is a control flow statement that allows you to continuously execute commands as long as a condition evaluates to true. In this article, we'll discuss what they are and how they work.
What is a While Loop
A while loop will execute some code as long as a certain condition is true. The code will keep executing as long as the condition does not evaluate to false. The first time the condition evaluates to true, it will execute and each time after that, it will only execute if the condition evaluates to true after running all of the code in the loop. While loop can be presented with flowchart maker like Zen Flowchart or other diagram software.
What is a For Loop
A for loop is similar to a while loop because it has the same three parts. The first part is initialization, which is executed once at the beginning of the loop. The second part is condition, which tells if the loop should continue to execute. The third part is incrementing, which happens right before each execution of the body of the for loop. Above is an example of a for-loop flowchart.