Learn to Program using Alice

Practice Test for the Lesson Titled

Sequence, Selection and Loop Structures

Published:  June 19, 2007
By Richard G. Baldwin

File: Alice0165PracticeTest.htm


Questions

1.  What is the value of x after the code in Listing 165-101 is executed?  (Hint:  ignore the word times.  It is misleading.)

Listing 165-101.
public void main ( ) {
  Number x = 0 ;
  for (int index=2; index< 7 times ; index++) {
    x .set( value , ( ( x + index ) ) );
  }
  print( x );
}
 

Answer and Explanation

2.  The loop shown in Listing 165-102:

Listing 165-102.
public void main ( ) {
  Number count = 1 ; Number sum = 0 ;
  while ( ( count < 10 ) ) {
    sum .set( value , ( ( sum + count ) ) );
    count .set( value , ( ( count + 1 ) ) );
  }
}
 

Answer and Explanation

3.  You have designed a program and have a number of steps which must be executed multiple times.  What is the program control structure most likely to be used to do this?   

Answer and Explanation

4.  True or False:  Structured programming is not important in modern computer programming.

Answer and Explanation

5.  True or False:  Any programming logic problem can be solved using an appropriate combination of only three programming structures.

Answer and Explanation

6.  True or False:  The three structures required by structured programming are known generally as:

Answer and Explanation

7.  True or False:  In structured programming, a section of program code must have only one entry point, but there may be multiple exit points. 

Answer and Explanation

8.  True or False:  In structured programming, structures may be nested inside of other structures provided that every structure meets the basic rules for a structure.

Answer and Explanation

9.  True or False:  The general requirement for the sequence structure is that one or more actions may be performed in sequence after entry and before exit.

Answer and Explanation

10.  True or False:  In a sequence structure, one or more of the action elements may themselves be sequence, selection, or loop structures.

Answer and Explanation

11.  True or False:  The selection or decision structure can be described as shown in the pseudocode in Figure 165-11.

Figure 165-11. The selection structure in pseudocode.
Enter
  Test a condition for large or small
  On large 
    Take one or more actions in sequence
  On small
    Take none, one, or more actions in sequence
Exit

Answer and Explanation

12.  True or False:  For a selection structure, when all of the actions for a chosen branch have been completed in sequence, control is transferred to the other branch of the selection structure.

Answer and Explanation

13.  True or False:  For a selection structure, it is often the case that no action is required when the test returns false.  In that case, control simply exits the structure without performing any actions.

Answer and Explanation

14.  True or False:  The loop or iteration structure can be described as shown in the pseudocode in Figure 165-14.

Figure 165-14. The loop structure in pseudocode.
Enter
  Test a condition for true or false
  Exit on false
  On true
    Perform one or more actions in sequence.
    Go back and test the condition again

There is only one entry point and one exit point for a loop structure.

Answer and Explanation

15.  True or False:  For a loop structure, unless something is done in one of the actions in the body of the loop to cause the test to eventually return false, control will never exit the loop.

In this case, the program will be caught in what is commonly referred to as a finite loop.

Answer and Explanation

16True or False:  In some programming languages, there are a couple of structures other than sequence, selection, and loop that structured-programming experts are willing to accept for convenience:

These structures are not required for the solution of programming logic problems.  Also, they are not support by Alice 2.0.

Answer and Explanation

17True or False:  To create a selection structure in Alice, begin by dragging the if tile from the object tree and dropping it at the appropriate location in the edit pane.

Answer and Explanation

18True or False:  When constructing a selection structure in Alice 2.0, the expression that you place in the conditional clause is the expression that will be evaluated to determine which part of the selection structure to execute.  If the expression in the conditional clause evaluates to true, the code between the curly braces before the else clause will be executed.  If the expression in the conditional clause evaluates to false, the code in the body of the else clause will be executed.

Answer and Explanation

19True or False:  To create a while loop structure in Alice, begin by dragging the loop tile from the bottom of the Alice development screen and dropping it at the appropriate location in the edit pane.

Answer and Explanation

20True or False:  As is the case with a selection structure, a loop structure has a conditional clause.

Answer and Explanation

21True or False:  Once the skeleton for a loop structure appears in your Alice code, you can replace the placeholder value with any expression that will evaluate to a value of type Number.

Answer and Explanation

22True or False:  The expression that you place in the conditional clause of a loop structure is the expression that will be evaluated to determine if the code in the body of the loop structure (the code between the curly braces) will be executed one time, or if the loop structure will terminate.

Answer and Explanation

23True or False:  If the expression in the conditional clause of a while loop structure evaluates to false, the code in the body of the loop will be executed once.  If the expression in the conditional clause evaluates to true, the loop will terminate immediately causing the code in the body of the loop to be skipped and causing the next statement following the body of the loop to be executed.

Answer and Explanation

24True or False:  The purpose of a priming read is to get the first input value before entering the loop so that the value can be used to determine the behavior of the loop during the first iteration.

Answer and Explanation

25True or False:  A while loop is  known as a pre-test or entry-condition loop.  This is because the conditional test is performed before the code in the body of the loop is executed.  If the test returns false the first time that it is performed, the code in the body of the loop won't be executed.

Other programming languages such as Java, C++, and C# also have an exit-condition loop, known as a do-while loop.  The major significance of the exit-condition loop is that the code in the body of the loop will be executed at least once, even if the test returns false the first time that it is performed.  This is because the test is performed after the body of the loop has already executed once.

Alice does not have an exit-condition loop.

Answer and Explanation

26True or False:  If you drag the loop tile (instead of the while tile) from the bottom of the Alice development screen and drop it into the edit pane, a for loop will be created.  A for loop is an exit-condition loop.  The code in the body of the loop will continue to execute for as long as the conditional clause evaluates to true.

Answer and Explanation



Copyright 2007, Richard G. Baldwin.  Faculty and staff of public and private non-profit educational institutions are granted a license to reproduce and to use this material for purposes consistent with the teaching process.  This license does not extend to commercial ventures.  Otherwise, reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.


The following image is the splash screen from Alice 2.0, and is the property of the developers of Alice at Carnegie Mellon.

Answers and Explanations


Answer 26

False

Explanation 26

Back to Question 26
 


Answer 25

True

Explanation 25

Back to Question 25
 


Answer 24

True

Explanation 24

Back to Question 24
 


Answer 23

False

Explanation 23

Back to Question 23
 


Answer 22

True

Explanation 22

Back to Question 22
 


Answer 21

False

Explanation 21

Back to Question 21
 


Answer 20

True

Explanation 20

Back to Question 20
 


Answer 19

False

Explanation 19

Back to Question 19


Answer 18

True

Explanation 18

Back to Question 18


Answer 17

False

Explanation 17

Back to Question 17


Answer 16

True

Explanation 16

Back to Question 16


Answer 15

False (infinite, not finite)

Explanation 15

Back to Question 15


Answer 14

True

Explanation 14

Back to Question 14


Answer 13

True

Explanation 13

Back to Question 13


Answer 12

False

Explanation 12

Back to Question 12


Answer 11

False

Explanation 11

Back to Question 11


Answer 10

True

Explanation 10

Back to Question 10


Answer 9

True

Explanation 9

Back to Question 9


Answer 8

True

Explanation 8

Back to Question 8


Answer 7

False

Explanation 7

Back to Question 7


Answer 6

True

Explanation 6

Back to Question 6


Answer 5

True

Explanation 5

Back to Question 5


Answer 4

False

Explanation 4

Back to Question 4


Answer 3

C. repetition or loop

Explanation 3

Back to Question 3


 

Answer 2

C. will exit (terminate) when count = 10.

Explanation 2

Back to Question 2


Answer 1

C. 20

Explanation 1

Back to Question 1


Copyright 2007, Richard G. Baldwin.  Faculty and staff of public and private non-profit educational institutions are granted a license to reproduce and to use this material for purposes consistent with the teaching process.  This license does not extend to commercial ventures.  Otherwise, reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

The following image is the splash screen from Alice 2.0, and is the property of the developers of Alice at Carnegie Mellon.

-end-