COMP1 Lab Act4. Algorithm Loop CS For Do While v2
COMP1 Lab Act4. Algorithm Loop CS For Do While v2
This activity aims to develop programming skills using loop control structures for and do-while.
2. Intended Learning Outcomes (ILOs):
The students should be able to:
2.1 Explain the for and do/while repetition control structures.
2.2 Apply the for and do/while repetition structures in the algorithm exercises.
3. Discussions
expression1;
while (expression2)
{ statement
expression3;
}
**As discussed from Laboratory Activity 3.
Many programmers prefer to use the form counter++ because the incrementing occurs after the loop
body is executed.
Exercise: Try to create an output of the following:
1. for (i = 1; i <= 10; i++)
2. for (i = 100; i>= 1; i--)
3. for (i = 7; i <=77; i += 7)
4. for (i = 20; i >=2; i-= 2)
5. for (i = 2; i <= 20; i+=3)
6. for (i = 99; i >= 0; i -= 11)
while ( condition)
is normally regarded as the header to a while structure. A do/while with no braces around the single
statement body appears as
do
statement
while (condition);
which can be confusing. The last line - while (condition); may be misinterpreted by the reader as a while
structure containing an empty statement. Thus, the do/while with one statement is often written as follows
to avoid confusion:
do {
statement
} while (condition);
4. Resources:
Personal Computer
Word App
Visio Software
5. Activities:
Prepare a pseudo code, flowchart, and create a program using do-while and for statements on the
following problems:
To log in to facebook account we first enter the facbook URL www.facebook.com in our browser
like Google, Firefox, Safari, Internet Explorer etc. This request is sent to the facebook server and
it responds by sending us the home page of facebook.
Next, we enter our registered Email ID and Password and click the Login button.
Then our login credential is checked. If it is correct, we are show our profile. On the other hand, if
the login credential is wrong then an error occurs and we are prompted to re-enter our Email ID and
Password. There are only 3 tries to log in the facebook account. In case after the third try log-in
credentials are still wrong, send an error message and terminate the process.
6. Assessment (Rubric for Laboratory Performance):