Professional Documents
Culture Documents
+ FLOW
CONTROL
OPERATORS
Create a program to check whether an integer is positive or negative. This program considers
0 as a positive number
FOR LOOP
for loops, are great for when you already know how
many times you want to loop through something. When
using a for loop, we typically use a counter that will
either increment or decrement until a condition is met.
Once the condition is met, the loop will stop. The
image below should give you a basic understanding of
how a for loop works.
Syntax
for (initialization; condition; update) {
// body of-loop
}
RANGE BASED LOOP
WHILE LOOP A while loop is slightly different than a for loop for
the fact that it’s good to use when we don’t know
how many times we want to loop through a problem
beforehand. This is the key difference between using
a for loop or a while loop. To get a basic idea of how
a while loop works, take a look at the image below.
Syntax:
while (condition) {
// body of the loop
}
DO WHILE LOOP A similar way to set up a while loop is with a do…while.
A do…while statement is similar to a while loop in the
fact that it will continue to run until the condition
becomes false. The only difference is the order in which
the loop runs. Here’s a simple example of a do…while
statement:
do {
// body of loop;
while (condition);
PLEASE VISIT PROGRAMIZ C++
TUTORIALS
https://www.programiz.com/cpp-programming/do-while-loop