ITC 112 Module 4 Computer Programming 1 Lesson 123
ITC 112 Module 4 Computer Programming 1 Lesson 123
Full name:
Date Submitted:
Problems Encountered:
Computer Programming 1
Module 4
Objectives
At the end of this module, you should be able to:
• Learn syntax in switch statement and able to read and write
• Learn syntax in java do-while loop and able to read and write
• Knowledgeable to read and write for loop
Control Structures
Lesson 1: Java Switch Statements
Lesson 2: Java While Loop
Lesson 3: Java For Loop
Computer Programming 1
Module 4
Lesson 1
ACTIVITY #1
Example for switch
Computer Programming 1
Module 4
Computer Programming 1
Module 4
Break statements are used when you want your program-flow to come out of the
switch body. Whenever a break statement is encountered in the switch body, the
execution flow would directly come out of the switch, ignoring rest of the cases
Let’s take the same example but this time with break statement.
Computer Programming 1
Module 4
Direction: Write your answer in a NetBeans 8.2 or AIDE application and screenshots your Java code
and Output, and don’t forget to write your Complete name in a Java comment type just like this
example: //Jeson Paglinawan ACT1 Lesson 1
1. Write a Java program using AIDE or NetBeans app the following examples above from Activity # 1
to Activity # 4. Explain each Activities, take note: Your own thoughts/idea so that I can determine
what you learned.
Direction: Write in your NetBeans 8.2 or AIDE application the following and Screenshot
your code/program, output and don’t forget to write your name in a Java comment just like
this example// Juan Dela Cruz ACT1-Application Lesson 1
Computer Programming 1
Module 4
Lesson 2
statement1;
statement2;
...
The statements inside the while loop are executed as long as the boolean_expression evaluates to true.
Computer Programming 1
Module 4
The Java while loop is used to iterate a part of the program several times. If the number of iteration
is not fixed, it is recommended to use while loop.
Syntax:
1. while(condition){
2. //code to be executed
3. }
Output:
Read & Analyze
1 Iteration Variable Condition Action
2 i<=10
3 1st i=1 true 1 is printed. 1 is increased to 2.
4 2nd i=2 true 2 is printed. 2 is increased to 3.
5 3rd i=3 true 3 is printed. 3 is increased to 4.
6 4th i=4 true 4 is printed. 4 is increased to 5.
7
5th i=5 true 5 is printed. 5 is increased to 6.
8
9 6th i=6 true 6 is printed. 6 is increased to 7.
10 7th i=7 true 7 is printed. 7 is increased to 8.
8th i=8 true 8 is printed. 8 is increased to 9.
9th i=9 true 9 is printed. 9 is increased to 10.
10th i=10 true 10 is printed. 10 is increased to 11.
11th i=11 false The loop is terminated
Computer Programming 1
Module 4
Direction: Write your answer in a NetBeans 8.2 or AIDE application and screenshots your Java code
and Output, and don’t forget to write your Complete name in a Java comment type just like this
example: //Jeson Paglinawan ACT1 Lesson 2
1. Write a Java program using AIDE or NetBeans app the following examples above from Activity # 1
to Activity # 6. Explain each Activities, take note: Your own thoughts/idea so that I can determine
what you learned.
Direction: Write in your NetBeans 8.2 or AIDE application the following and Screenshot your
code/program, output and don’t forget to write your name in a Java comment just like this
example// Juan Dela Cruz ACT1-Application Lesson 2
1. Write a java program that can display/Output your name five times. Using while loop and with do-
while loop.
Example Output: // while loop Example Output: // do-while loop
Juan Dela Cruz Juan Dela Cruz
Juan Dela Cruz Juan Dela Cruz
Juan Dela Cruz Juan Dela Cruz
Juan Dela Cruz Juan Dela Cruz
Juan Dela Cruz Juan Dela Cruz
Computer Programming 1
Module 4
Lesson 3
Flow of Execution of the for Loop First step: In for loop, initialization happens
As a program executes, the interpreter always keeps track first and only one time, which means that
of which statement is about to be executed. We call this the initialization part of for loop only
the control flow, or the flow of execution of the program. executes once.
The Java for loop is used to iterate a part of the program several times. If the number of iteration
is fixed, it is recommended to use for loop.
Java for loop is used to run a block of code for a certain number of times. The syntax
of for loop is:
Here,
int n = 5;
// for loop
for (int i = 1; i <= n; ++i) {
System.out.println("Java is fun");
}
}
}
Java is fun
Java is fun
Java is fun
Java is fun
Computer Programming 1
Java is fun
Flowchart of Java for loop
Module 4
Explanation for Example 1: Display a Text Five Times
Direction: Write your answer in a NetBeans 8.2 or AIDE application and screenshots your
Java code and Output, and don’t forget to write your Complete name in a Java comment
type just like this example: //Jeson Paglinawan ACT1 Lesson 3
1. Write a Java program using AIDE or NetBeans app the following examples above from
Activity # 1 to Activity # 4. Explain each Activities, take note: Your own thoughts/idea so that
I can determine what you learned.
Direction: Write in your NetBeans 8.2 or AIDE application the following and Screenshot
your code/program, output and don’t forget to write your name in a Java comment just
like this example// Juan Dela Cruz ACT1-Application Lesson 3
1. Write a Java program that can display/Output your Full name course and
year in a 8 times. Using For Loop, and Explain? Expected Output: Juan Dela Cruz Act 1
Juan Dela Cruz Act 1
Juan Dela Cruz Act 1
Juan Dela Cruz Act 1
Juan Dela Cruz Act 1
Juan Dela Cruz Act 1
2. Write a java program that can display/Output Juan Dela Cruz Act 1
numbers from 5 to 1. Using for loop, and Explain? Juan Dela Cruz Act 1
Hint: Use decrement
Expected Output: 5
Example: x- -;
4
3
2
1
Computer Programming 1
Module 4
Reference:
https://www.programiz.com/java-programming/do-while-loop
Useful Resources:
https://www.w3schools.com/java/java_while_loop.asp https://www.youtube.com/watch?v=wcwWlasmLWs
https://www.tutorialspoint.com/java/switch_statement_in_jav https://www.youtube.com/watch?v=0OGlp3J6drs
a.htm#:~:text=Advertisements,is%20checked%20for%20each% https://www.youtube.com/watch?v=QneahuoJ41A
20case. https://www.youtube.com/watch?v=z-WHCK68t2I
https://www.geeksforgeeks.org/java-while-loop-with- https://www.youtube.com/watch?v=MYqeVgtXa1I
examples/#:~:text=Java%20while%20loop%20is%20a,on%20a% https://www.youtube.com/watch?v=6djggrlkHY8
20given%20Boolean%20condition. https://www.youtube.com/watch?v=g8GcFboF2rM
&text=If%20the%20condition%20evaluates%20to,and%20go% https://www.youtube.com/watch?v=aaL-mc2BLSI
20to%20update%20expression. https://www.youtube.com/watch?v=oAl0umTfW4U
https://beginnersbook.com/2015/03/for-loop-in-java-with- https://www.youtube.com/watch?v=cakN0XC6CcQ
example/ https://www.youtube.com/watch?v=GwcisLY5avc
https://www.geeksforgeeks.org/switch-statement-in-
java/#:~:text=The%20switch%20statement%20is%20a,and%20i
nt%20primitive%20data%20types.
https://www.javatpoint.com/java-for-loop
https://www.programiz.com/java-programming/do-while-loop
https://www.w3schools.com/java/java_switch.asp
https://www.w3schools.com/java/java_while_loop.asp
https://www.w3schools.com/java/java_for_loop.asp
Computer Programming 1
Module 4
Answer Sheet
Computer Programming 1
Module 4
Answer Sheet
Computer Programming 1