Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

APP DEV | Activity 6

Give the syntax for the following looping statements:


1. While - the while loop repeatedly executes the block of code if condition is true.
while (condition) {
// Statements to execute
}
2. Do/While - the do/while loop executes the block of code once and continues to execute it if it
remains true.
do {
// Statements to execute
} while (condition);
3. For - allows to give an initialization, condition, and expression in one line.
for (initialization; testExpression; updateStatement) {
// Statements to execute
}
4. For-Each - iterates over elements in array or list.
for (type var : array)
{
statements using var;
}
5. Explain the use of the Break statement in the looping statements.
 Break statement is used to terminate the execution of loop. It is used as an exit in a loop
when a condition is met.
for (int i = 0; i < 10; i++) {
if (i == 5) {
break; // Exit the loop when i reaches 5
}
printf("Value of i: %d\n", i);
}
6. Explain the use of the Continue statement in the looping statements.
 Continue statement is used to skip the iteration of a loop to go to next iteration.
for (int j = 0; j < 10; j++) {
if (j % 2 == 0) {
continue; // Skip even numbers
}
printf("Odd number: %d\n", j);
}

You might also like