Description: [The while, for, and do-while Loops]. Introduction to the use of repetitive structures: the while, for, and do-while loop. Demonstration of the uses of the three kinds of loops.
Code (Needs Javas):
ACM CCECC
N/A
AP CS A
[for Loops (including nested)]
CON-2.E Represent iterative processes using a for loop.
CON-2.E.1 There are three parts in a for loop header—the initialization, the Boolean expression, and the increment. The increment statement can also be a decrement statement.
CON-2.E.2 In a for loop, the initialization statement is only executed once before the first Boolean expression evaluation. The variable being initialized is referred to as a loop control variable.
CON-2.E.3 In each iteration of a for loop, the increment statement is executed after the entire loop body is executed and before the Boolean expression is evaluated again.
CON-2.E.4 A for loop can be rewritten into an equivalent while loop and vice versa.
CON-2.E.5 “Off by one” errors occur when the iteration statement loops one time too many or one time too few.
CON-2.C.2 In loops, the Boolean expression is evaluated before each iteration of the loop body, including the first. When the expression evaluates to true, the loop body is executed. This continues until the expression evaluates to false, whereupon the iteration ceases.
[while Loop]
CON-2.C.4 If the Boolean expression evaluates to false initially, the loop body is not executed at all.
[do-while Loop]
CON-2.C.1 Iteration statements change the flow of control by repeating a set of statements zero or more times until a condition is met.
CS1
N/A
ACM CCECC
N/A
AP CS A
[For Loops (including nested)]
CON-2.C.5 Executing a return statement inside an iteration statement will halt the loop and exit the method or constructor.
[while Loop]
CON-2.C.3 A loop is an infinite loop when the Boolean expression always evaluates to true.
CS1
[Comparing String Objects]
N/A
Description: Demonstration of what standalone loops are capable of for algorithms that require and do not require the use of traversals. In this video, students will create a vowel counter for a given number of phrases by the user.
Code:
ACM CCECC
N/A
AP CS A
[For Loops (including nested)]
CON-2.D For algorithms in the context of a particular specification that does not require the use of traversals— a. Identify standard algorithms b. Modify standard algorithms c. Develop an algorithm
CON-2.F For algorithms in the context of a particular specification that involves String objects— a. Identify standard algorithms b. Modify standard algorithms c. Develop an algorithm
CON-2.F.1 There are standard algorithms that utilize String traversals to— ● Find if one or more substrings has a particular property ● Determine the number of substrings that meet specific criteria ● Create a new string with the characters reversed
CS1
[Comparing String Objects]
N/A
Description: In the first video, we demonstrate how to read a file using the Scanner. In this session, the Scanner methods .nextLine(), .next(), and .nextInt() are essential, along with the use of a basic exception handling statement.
In the second video, we now demonstrate how to write a file by using a File object and importing the PrintWriter. Importing libraries such as java.util.* and java.io.* is vital for the purpose of this demonstration.
Code (Video 1):
Code (Video 2):
ACM CCECC
[Files]
SDF-08. Create a simple program that uses persistence to save data across multiple executions.
AP CS A
[for Loops (including nested)]
CON-2.G Represent nested iterative processes.
CON-2.G.1 Nested iteration statements are iteration statements that appear in the body of another iteration statement.
CON-2.G.2 When a loop is nested inside another loop, the inner loop must complete all its iterations before the outer loop can continue.
CS1
[while Loop]
130.421.c.4.t Develop iterative algorithms and code programs to solve practical problems;
Description: Two different approaches on how to generate random numbers using Java.
Method 1: using the Math library and the method random(). This method requires some "manipulation" since the Math.random() generates random numbers [0,1) not including 1. It also generates double numbers, and it might require to use of type-casting to manipulate the data type.
Method 2: using the Random object from java. It is required to import the library: import java.util.Random; This object contains several methods, including .nextInt(). This method avoids the manipulation from the previous method, however, it requires the usage of the object Random.
Code:
ACM CCECC
[Random Numbers]
AL-06. Investigate the use of random/pseudo-random number generation in cybersecurity applications.
AP CS A
[while Loop]
CON-2.H Compute statement execution counts and informal run-time comparison of iterative statements.
CON-2.H.1 A statement execution count indicates the number of times a statement is executed by the program.
[do-while Loop]
CON-2.C.1 Iteration statements change the flow of control by repeating a set of statements zero or more times until a condition is met.
[Random Numbers]
CON-1.D.4 The values returned from Math.random can be manipulated to produce a random int or double in a defined range
CS1
[Random Numbers]
130.421.c.4.w Generate and use random numbers.