What is the increment operation used in the loop?
i++;
When does the for loop terminate?
When 'i' becomes 10.
1/131
p.17
While Loop Basics

What is the increment operation used in the loop?

i++;

p.19
For Loop Syntax and Usage

When does the for loop terminate?

When 'i' becomes 10.

p.21
Variable Scope in Loop Control

What is the initial value of the variable 'sum'?

0.

p.7
Loop Control Examples

What happens to the variable 'sum' during each iteration of the loop?

It accumulates the total of the input values.

p.14
User Input in Loops

What is the significance of the 'Scanner' class in this program?

It is used to take user input from the console.

p.23
Loop Control Examples

What values does the second loop output?

7, 14, 21, …, 77.

p.8
User Input in Loops

In the next example after WhileEg2, what does the program do instead of asking the user for input?

It checks the data entered by the user to determine if the loop should continue.

p.11
Logic Errors in Loops

What is the main issue with the first loop provided?

The loop executes only 9 times instead of 10 because it starts counting from 1 and stops before reaching 10.

p.11
Logic Errors in Loops

How can you fix the first loop to execute 10 times?

Change the condition to 'count <= 10' or initialize count to 0 and use 'count < 10'.

p.1
While Loop Basics

Can you name a common type of repetition structure?

While loop.

p.21
While Loop Basics

What is the purpose of the program in RewriteWhileEg2?

To calculate the sum of a specified number of values input by the user.

p.24
For Loop Syntax and Usage

Where should the counter variable be declared for a for loop in C?

Before the for statement or inside the for statement.

p.23
Loop Control Examples

What is the starting point and condition of the second loop example?

Starts at 7 and increments by 7 until it reaches 77.

p.25
Common Pitfalls in Loop Structures

Who prepared the document associated with '25 (C) VTC'?

sm-lau@vtc.edu.hk.

p.25
Common Pitfalls in Loop Structures

What does 'END' signify in a document?

It indicates the conclusion or termination of the content.

p.3
Infinite Loops and Logic Errors

Can a while loop create an infinite loop?

Yes, if the condition never becomes false.

p.23
Loop Control Examples

What is the starting point and condition of the first loop example?

Starts at 100 and decrements until it reaches 1.

p.1
While Loop Basics

What is a key characteristic of a while loop?

It continues to execute as long as a specified condition is true.

p.19
For Loop Syntax and Usage

What happens to 'i' after each iteration of the loop?

'i' is incremented.

p.19
For Loop Syntax and Usage

What is checked after each loop iteration?

The loop condition is checked again.

p.20
For Loop Syntax and Usage

What is the purpose of the first for-loop example?

To sum all numbers from 1 to 100.

p.10
Infinite Loops and Logic Errors

What sequence does 'count' follow in the while-loop example?

1, 3, 5, 7, 9, 11, ...

p.7
While Loop Basics

How does the while loop in the program function?

It continues to prompt for values until 'i' is less than 'n'.

p.15
Do-While Loop Structure

How can the WhileEg3 program be rewritten using a do-while loop?

By prompting for input first, adding to the sum, and then checking the condition in the while statement.

p.15
Do-While Loop Structure

Why might using a do-while loop be considered simpler in this example?

Because it guarantees that the user is prompted for input at least once before checking the condition.

p.25
Common Pitfalls in Loop Structures

What does '25 (C) VTC' refer to?

It likely refers to a course or document identifier from the Vocational Training Council.

p.1
While Loop Basics

What are repetition structures in programming?

They are constructs that allow a block of code to be executed multiple times.

p.4
While Loop Basics

What happens if the boolean condition in a while loop evaluates to true?

The loop_body is executed.

p.22
For Loop Syntax and Usage

What is the output range of the loop 'for (int i=0; i<=100; i++) { … }'?

0, 1, 2, 3, …, 99, 100

p.17
While Loop Basics

What condition is checked in the while-loop?

i < 10.

p.16
For Loop Syntax and Usage

What is an example of a typical 'for' loop syntax?

'for (initialization; condition; increment) { // code }'

p.6
While Loop Basics

How many times does the loop body execute in WhileEg1?

It executes till and including i = 3.

p.6
User Input in Loops

In the next example after WhileEg1, how is the number of iterations determined?

It is determined by the user during run-time.

p.9
User Input in Loops

How does the program read user input?

Using the Scanner class to read integers from the keyboard.

p.21
For Loop Syntax and Usage

What type of loop is used in the RewriteWhileEg2 program?

A for loop.

p.9
Variable Scope in Loop Control

What is the initial value of 'sum' before any inputs are processed?

0.

p.15
Common Pitfalls in Loop Structures

What is a potential deficiency of the original program?

It does not handle the case where the first input is non-positive, resulting in a sum of 0 without any user interaction.

p.18
For Loop Syntax and Usage

What condition is checked in the for loop?

i < 10.

p.3
While Loop Basics

What is the primary function of a while statement in programming?

To execute a block of code repeatedly as long as a specified condition is true.

p.3
While Loop Basics

What happens if the condition in a while statement is false?

The block of code inside the while loop will not execute.

p.6
While Loop Basics

How is the number of times the loop body executed in WhileEg1 determined?

It is set directly in the program source.

p.9
While Loop Basics

What is the purpose of the WhileEg3 program?

To calculate the sum of positive integer inputs until a non-positive integer is entered.

p.4
While Loop Basics

What happens while the condition remains true in a while loop?

The loop_body is executed repeatedly.

p.12
Do-While Loop Structure

What happens if the condition in a do-while loop is false?

The loop will terminate after executing the code block once.

p.24
For Loop Syntax and Usage

What is the correct way to declare a counter variable before the for loop?

int i; for (i=1; i<=10; i++) System.out.println(i);

p.24
For Loop Syntax and Usage

What is the correct way to declare a counter variable inside the for loop?

for (int i=1; i<=10; i++) System.out.println(i);

p.5
While Loop Basics

What is the condition for the while-loop to continue executing?

i < 4.

p.18
While Loop Basics

What condition is checked in the while loop?

i < 10.

p.20
For Loop Syntax and Usage

What does 'sum += num;' do in the first for-loop?

It adds the current value of 'num' to 'sum'.

p.20
For Loop Syntax and Usage

What is the increment step for 'num' in the second for-loop?

num is incremented by 2.

p.12
Comparing While and For Loops

How does a do-while loop differ from a while loop?

A do-while loop checks the condition after executing the code block, while a while loop checks the condition before executing.

p.6
While Loop Basics

What is the starting value of 'i' in the WhileEg1 example?

i = 1.

p.9
While Loop Basics

What does the variable 'sum' represent in the program?

It accumulates the total of the positive integers entered by the user.

p.4
While Loop Basics

What happens when the condition in a while loop becomes false?

The next_statement is executed.

p.21
Variable Scope in Loop Control

What is the role of the variable 'n' in the program?

It stores the number of values the user wants to input.

p.15
Do-While Loop Structure

What does the WhileEg3 program do?

It sums positive integers input by the user until a non-positive integer is entered.

p.20
For Loop Syntax and Usage

What is the initial value of 'num' in the first for-loop?

1.

p.15
While Loop Basics

What is the output of the program when the input values are 3, 10, 20, and 0?

Sum = 33.

p.19
For Loop Syntax and Usage

What is the statement executed after the loop body?

System.out.println("I am next_statement");

p.18
For Loop Syntax and Usage

What is the initial value of 'i' in the for loop example?

int i = 0;

p.18
For Loop Syntax and Usage

What is the increment operation used in the for loop?

i++;

p.2
Structure Theorem in Programming

How many basic control structures are defined in the Structure Theorem?

Three.

p.13
Do-While Loop Structure

What happens after the loop body in a do-while loop?

The boolean condition is checked.

p.11
Logic Errors in Loops

What is the issue with the second loop?

The loop executes only 9 times because it starts counting from 0 and stops before reaching 9.

p.12
Do-While Loop Structure

What is the syntax structure of a do-while loop?

do { // code block } while (condition);

p.6
While Loop Basics

What is the condition for the loop to continue in WhileEg1?

The condition is i < 4.

p.22
For Loop Syntax and Usage

What is the output range of the loop 'for (int i=1; i<=100; i++) { … }'?

1, 2, 3, …, 99, 100

p.4
While Loop Basics

What is the general syntax of a while loop?

while (condition) loop_body; next_statement;

p.19
For Loop Syntax and Usage

What are the values of 'i' during the loop execution?

'i' changes as 0, 1, 2, 3, …, 9.

p.14
Do-While Loop Structure

What does the variable 'n' represent in the code?

The number of values the user wants to input.

p.19
For Loop Syntax and Usage

What is the output statement inside the loop?

System.out.println("I am loop_body");

p.20
For Loop Syntax and Usage

What is the purpose of the second for-loop example?

To sum all odd numbers between 0 and 100.

p.7
User Input in Loops

What type of input does the program expect from the user?

Integer values.

p.16
For Loop Syntax and Usage

What are the three main components of a 'for' loop?

Initialization, condition, and increment/decrement.

p.10
Infinite Loops and Logic Errors

What is an infinite loop?

A loop that will never terminate because the boolean expression will never become false.

p.23
Loop Control Examples

What values does the first loop output?

100, 99, 98, …, 1.

p.1
While Loop Basics

What is an example of a situation where repetition structures are useful?

When processing items in a list until the end is reached.

p.17
While Loop Basics

What statement is executed after the loop body?

System.out.println("I am next_statement");

p.14
Do-While Loop Structure

What is the purpose of the 'do-while' loop in the provided Java code?

To repeatedly prompt the user for a value and sum it until a specified number of inputs is reached.

p.15
While Loop Basics

How does the while loop in the program function?

It continues to prompt for input and adds to the sum as long as the input value is greater than 0.

p.14
Do-While Loop Structure

What is the initial value of the variable 'i' in the code?

0.

p.18
While Loop Basics

What is the increment operation used in the while loop?

i++;

p.20
For Loop Syntax and Usage

What is the condition for 'num' in the second for-loop?

num must be less than 100.

p.8
User Input in Loops

What does the program in WhileEg2 ask the user for?

The number of times the loop is needed (value of n).

p.13
Do-While Loop Structure

What is the basic syntax of a do-while loop?

do { loop_body; } while (condition);

p.1
While Loop Basics

What is the purpose of repetition structures?

To perform tasks repeatedly until a certain condition is met.

p.4
While Loop Basics

What occurs after executing the loop_body in a while loop?

The condition is tested again.

p.19
For Loop Syntax and Usage

What is the initial value of 'i' in a for loop?

i starts with 0.

p.10
Infinite Loops and Logic Errors

What is the initial value of 'product' in the given while-loop example?

0.

p.5
While Loop Basics

What is the initial value of 'i' in the program?

1.

p.5
While Loop Basics

What is the final value of 'sum' after the while-loop execution?

6.

p.18
While Loop Basics

What is the initial value of 'i' in the while loop example?

i = 0.

p.9
While Loop Basics

What is the output of the program if the user inputs 3, 10, 20, and then 0?

Sum = 33.

p.24
For Loop Syntax and Usage

What happens if the counter variable is declared incorrectly?

It results in an invalid declaration.

p.18
For Loop Syntax and Usage

What is the syntax for a for loop?

for (initialization; condition; increment) { }

p.20
For Loop Syntax and Usage

What is the initial value of 'num' in the second for-loop?

1.

p.16
For Loop Syntax and Usage

What is the primary purpose of the 'for' statement in programming?

To execute a block of code a specific number of times.

p.13
Do-While Loop Structure

In a do-while loop, when does the loop stop executing?

When the boolean condition evaluates to false.

p.5
While Loop Basics

What does the program in Example 1 calculate?

The sum of 1 + 2 + 3.

p.22
For Loop Syntax and Usage

What is the syntax for a for loop in C that starts from 1 and goes to 99?

for (int i=1; i<100; i++) { … }

p.17
While Loop Basics

What happens inside the loop body?

System.out.println("I am loop_body"); i++;

p.12
Infinite Loops and Logic Errors

Can a do-while loop create an infinite loop?

Yes, if the condition always evaluates to true.

p.10
Infinite Loops and Logic Errors

What is the initial value of 'count' in the second while-loop example?

1.

p.7
User Input in Loops

What does the variable 'n' represent in the program?

The number of values the user wants to input.

p.20
For Loop Syntax and Usage

What condition must 'num' satisfy in the first for-loop?

num must be less than or equal to 100.

p.14
Do-While Loop Structure

What happens inside the 'do' block of the loop?

The program prompts the user for a value, adds it to the sum, and increments 'i'.

p.14
Do-While Loop Structure

How does the 'while' condition affect the loop's execution?

The loop continues until 'i' is less than 'n'.

p.18
For Loop Syntax and Usage

What is the output statement inside the for loop?

System.out.println("I am loop_body");

p.2
Structure Theorem in Programming

What does the Structure Theorem state?

It is possible to write ANY computer program using only three basic control structures.

p.12
Do-While Loop Structure

What is the primary purpose of a do-while statement?

To execute a block of code at least once before checking a condition.

p.17
While Loop Basics

What is the initial value of 'i' in the while-loop example?

i = 0.

p.16
Comparing While and For Loops

How does the 'for' loop differ from a 'while' loop?

A 'for' loop is typically used when the number of iterations is known, while a 'while' loop is used when the number of iterations is not predetermined.

p.5
While Loop Basics

How many times is the while-loop body executed in the program?

3 times.

p.9
While Loop Basics

What condition must be met for the while loop to continue executing?

The value must be greater than 0.

p.9
While Loop Basics

What happens when the user inputs a value of 0?

The while loop terminates and the program outputs the sum.

p.21
Loop Control Examples

How is the sum of the values calculated in the program?

By using a for loop to iterate through the user inputs and adding each value to the sum.

p.17
While Loop Basics

What is the structure of a while-loop in C?

while (condition) { loop_body }

p.18
While Loop Basics

What is the output statement inside the while loop?

System.out.println("I am loop_body");

p.14
Do-While Loop Structure

What is printed as the final output of the program?

The total sum of the values entered by the user.

p.13
Do-While Loop Structure

What is the main difference between a do-while loop and a while loop?

The do-while loop executes the loop body once before checking the boolean condition.

p.22
For Loop Syntax and Usage

What is the syntax for a basic for loop in C that iterates from 0 to 99?

for (int i=0; i<100; i++) { … }

p.3
Infinite Loops and Logic Errors

What is essential to avoid infinite loops in while statements?

Ensure that the loop condition will eventually become false.

p.11
Logic Errors in Loops

How can you modify the second loop to execute 10 times?

Change the condition to 'count < 10'.

p.21
User Input in Loops

What does the user input in the program?

The number of values to sum and the values themselves.

p.10
Infinite Loops and Logic Errors

What happens to 'product' in the while-loop example?

'product' is always 0 because it is multiplied by 5 but never updated.

p.7
While Loop Basics

What is the purpose of the WhileEg2 program?

To calculate the sum of a specified number of values input by the user.

p.24
For Loop Syntax and Usage

Is declaring the counter variable inside the for loop valid?

Yes, it is valid.

p.24
For Loop Syntax and Usage

Is declaring the counter variable outside the for loop valid?

Yes, it is valid.

p.7
Variable Scope in Loop Control

What is the initial value of the variable 'i'?

0.

p.7
While Loop Basics

What is printed at the end of the program?

The total sum of the input values.

p.7
Common Pitfalls in Loop Structures

What will happen if the user inputs a number less than 1 for 'n'?

The loop will not execute, and the sum will remain 0.

Study Smarter, Not Harder
Study Smarter, Not Harder