0
Still don't get the looping techniques. Need help
2 Answers
0
Its very easy, let me know how can I help, there ase a few loop functions that can be used
- 1
All flow control statements sans goto (if, while, for) basically change how the following line or block is executed, a block being a set of instructions enclosed by curly braces.
While loops will evaluate the condition given, and if it's true, runs the line or block. Do statements don't have a condition but require a while afterwards with a condition statement, which is run after the line/block.
int x = 0;
while (x < 3)
{
std::cout << x << " ";
x++;
}
std::cout << std::endl;
x = 0;
do
{
std::cout << x << " ";
x++;
} while (x < 3)
The while loop spits out 0 1 2 while the do loop writes 0 1 2 3.
The for loop is basically the while loop, but has some optional extras for convenience sake. These snippets are functionally identical:
int x = 0;
while (x < 3)
{
x++;
std::cout << x << std::endl;
}
for (int x = 0; x < 3; x++)
{
std::cout << x << std::endl;
}
Hopefully that helps with any confusion.