From the course: C++ Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Loops - C++ Tutorial
From the course: C++ Essential Training
Loops
- The basic while loop control looks a lot like a simple if statement. In this case, the statement block will execute repeatedly until the condition is false. The flow of a while loop also looks a lot like an if statement. The difference is after the statement block is executed, flow returns back to the condition and this creates a loop. The loop only ends when the condition becomes false. This is while.cpp from chapter three of the exercise files. We have a basic while loop down here, beginning on line 13. And you notice that the block is lines 14 and 15, with the curly braces ending line 16. The condition is called the loop control, as it controls the execution of the loop. We have this array up here with five elements, the values of the elements are one, two, three, four, and five. Yet the index of the elements are zero through four. So we create a little index variable that we'll use to index the array. And we…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.