Professional Documents
Culture Documents
05 Laboratory Exercise 1
05 Laboratory Exercise 1
05 Laboratory Exercise 1
Conditions and Loops
Objectives:
Materials:
Basic Principles:
Conditions or conditional statements, and loops are used to control the program flow. With this
activity, the students will be knowledgeable on using these structures to develop program when a
condition occurs.
Procedures:
2. Add one Textbox, one Label and one Button Control to the form.
5. Copy the code below for button Show under the BtnShow_Click():
Dim x As Integer
x = txtNum.Text
If x Mod 2 = 0 Then
lblResult.Text = "The number is Even"
End If
7. Enter values which are multiple of 2. Click the Show button and observe what happens.
8. Enter values which are not multiple of 2. Click the Show button and observe if changes occur.
10. Insert the added code below, If Else conditional statement, for button Show:
Dim x As Integer
x = txtNum.Text
If x Mod 2 = 0 Then
lblResult.Text = "The number is Even"
Else
lblResult.Text = “The number is Odd”
End If
12. Enter values which are multiple of 2. Click the Show button and observe what happens. Then,
enter values which are not multiple of 2. Click the Show button and observe changes.
1. On the same project, change the Text Property of lblResult to Prime or Composite.
2. Replace the code in BtnShow under BtnShow_Click with the code below:
Dim x, y As Integer
Dim z As Boolean
x = txtNum.Text
z = True
For y = 2 To (x - 1)
If x Mod y = 0 Then
z = False
Exit For
End If
Next
If z Then
lblResult.Text = "It is a prime number"
Else
lblResult.Text = "It is a composite number"
End If
4. Enter values that can be divided only by 1 or itself like 5, 7, 11. Then click btnShow and
observe what happens.
5. Enter values that can be divided by numbers other than 1 and itself like 6, 9, 10. Then, click
the btnShow and observe what happens.
Challenged Exercise:
a) Infant – 0 to 2 years
b) Child – 3 to 9
c) Adolescent – 10 to 19
Figure 5.3 Form2
e) Adult – 30 to 39
f) Middle Age – 40 to 60
g) Elder – 60 onward
3. On the new Windows Form, with the use of loop, create a program that will display a Message
box starting with supplied value based from the entered start value and end to the entered end
value.
For example, the input start integer is 6 and the end integer is 12, so the Message box will
appear 7 times, first with value of 6, next is 7, then 8, 9, 10, 11, and 12.