1.
Question :
(TCO 5) When writing a program, if you know exactly how many times statements in a loop should execute, use the _____ structure.
do while
for
goto
while
2.
Question :
(TCO 5) When used within a loop structure, the _____ statement causes execution to jump out of the loop and proceed with subsequent statements in the program.
break
continue
goto
jump
3.
Question :
(TCO 5) A _____ looping structure, such as WHILE, performs its conditional expression _____ its contents execute.
posttest, after
pretest, before
posttest, while
pretest, while
4.
Question :
(TCO 10) During a code walk-through, someone may suggest that this code be replaced with _____, as it is more efficient.
int val = 0;
while (val < 10)
{
Console.WriteLine(val);
val++;
}
for(int val = 0; val < 10; val++)
{
Console.WriteLine(val);
}
for(int val = 0; val <= 10; val++)
{
Console.WriteLine(val);
}
for(int val = 0; val < 10; val–)
{
Console.WriteLine(val);
}
int val = 0;
do while (val < 10)
{
Console.WriteLine(val);
val++;
}
5.
Question :
(TCO 5) A block of statements within the body of a FOR loop must be surrounded with _____.
curly braces {}
parentheses ()
square brackets []
None of the above
6.
Question :
(TCO 5) What output will this set of statements produce?
int a = 1;
while (a < 1)
{
Console.Write(“{0}t”, a);
a++;
}
Console.Write(“{0}t”, a);
An infinite loop
An exception
1
1 1
7.
Question :
(TCO 5) In this code, the variable _____ is a counter and the variable _____ is an accumulator.
double total = 0, weight = 2.0, limit =10, max = 50;
int track = 0;
for (int num = 0; num <= limit; num++ )
{
total = total + weight * num;
if (total <= max)
track++;
}
num, track
total, track
track, total
weight, limit
8.
Question :
(TCO 5) In this code, the inner FOR loop _____.
int i = 1, j = 1;
for (i = 1; i < 4; i++)
{
for (j = 1; j < 4; j++)
{
Console.Write(“{0}{1} “, i, j);
}
}
contains a syntax error
is nested
executes three times
executes four times
9.
Question :
(TCO 5) Your program keeps asking for last names from the user until he/she enters “####.” In this context, the “####” is used as a(n) _____.
accumulator
counter
sentinel value
test value
11.
Question :
(TCO 5) Using a WHILE loop, write the C# code required to print every 2nd integer from 1 to 201 (i.e., 1, 3, 5, 7, etc.). Print each number on its own line.
CIS170 Week 3 study guide
CIS170A Week 3 study guide
CIS170B Week 3 study guide
CIS170C Week 3 study guide
–iqra javaid