Log in
Sign up for FREE
arrow_back
Library
4 - for & while loops
By Nathan Knauss
star
star
star
star
star
Share
share
Last updated about 4 years ago
13 questions
Add this activity
1
1
1
1
1
1
1
1
1
1
1
1
1
Question 1
1.
for loops are best suited for which of the following purposes?
Performing the same action on an increasingly smaller subset
Infinitely repeating actions
Counting
Actions repeating until a certain event occurs
Question 2
2.
Each time through a loop is called a(n)
Repeat
Go
Iteration
Fabulation
Question 3
3.
Which of the following is the right order of the parts of a for loop?
for( stop ; start ; step )
for( step ; start ; stop )
for( step ; stop ; start )
for( start ; stop ; step )
Question 4
4.
Which of the following counts through the numbers 0 to 9 inclusive?
for( int i=1; i<=9; i++ )
for( int i=1; i<=10; i++ )
for( int i=0; i<9; i++ )
for( int i=0; i<10; i++ )
Question 5
5.
Given the line of code:
i=i+1;
What can be said?
There are two steps in this code, first adding 1 to i then assigning the result back to i
This code won’t run because that is mathematically impossible
This code won’t run because i+1 is out of range
This is a loop within a single line that happens one more time
Question 6
6.
Which of the following has the same effect as
i++
?
i+1
i
i=i+1
I--
Question 7
7.
Why is it acceptable to use i as a counter variable?
That is conventional and common, i is short for “index”
I represents you, the programmer
i is short for “intensity” as in current
It is NOT acceptable
Question 8
8.
while loops are best suited for which of the following purposes?
Actions repeating until a certain event occurs
Counting
Infinitely repeating actions
Performing the same action on an increasingly smaller subset
Question 9
9.
Each time through a while loop is called a(n)
Iteration
Go
Repeat
Fabulation
Question 10
10.
Which of the following is the right template for a header line in a while loop?
Repeat
Go
Iteration
Fabulation
Question 11
11.
Which of the following is the right template for a header line in a while loop?
while( control_expression_is_false )
while
while( start ; stop ; step )
while( control_expression_is_true )
Question 12
12.
Which of the following counts through the numbers 0 to 9 inclusive?
int i=0;
while( i<9 )
{ i++; }
int i=0;
while( i<10 )
{ i++; }
int i=1;
while( i<=10 )
{ i++; }
int i=1;
while( i<=9 )
{ i++ }
Question 13
13.
What is wrong with the following code?
int i=0; while( i<100 ) {
Serial.println(i);
i++;
}
Serial.print("After the loop, i’s valuse is:");
Serial.println(i);
The variable i is out of scope after the while loop
The for loop header line is not formatted correctly
The variable i cannot be printed to the serial monitor
There isn’t anything wrong with this loop