Lecture 3
Lecture 3
Programming
Contents
• Increment/Decrement
• Loops
While
Do/While
For
• Break
• Continue
Increment/Decrement
• The do/while loop is a variant of the while loop. This loop will
execute the code block once, before checking if the condition is true,
then it will repeat the loop as long as the condition is true.
• Syntax-
do
{
// code block to be executed
}
while (condition);
Do/While Loop...
• When you know exactly how many times you want to loop through a
block of code, use the for loop instead of a while loop.
• Syntax-
for (statement 1; statement 2; statement 3)
{
// code block to be executed
}
For Loop...
int main() {
int main() {
for (int i = 0; i < 10; i++)
for (int i = 0; i < 10; i++)
{
{
if (i > 5)
if (i == 5)
{
{
break;
break;
}
}
cout << i << "\n";
cout << i << "\n";
}
}
return 0;
return 0;
}
}
Continue