The learner will review code and answer questions about loops.

For Loops

All flashcards in this set deal with the following code:

int timer = 200;
int currentPin;

void setup()
{
   for (currentPin = 0; currentPin < 8; currentPin++)
   {
   pinMode(currentPin, OUTPUT);
   }
}

void main()
{
   for (currentPin = 0; currentPin < 8; currentPin++)
   {
      digitalWrite(currentPin, HIGH);
      delay(timer);
      digitalWrite(currentPin, LOW);
   }
   for (currentPin = 7; currentPin >= 0; currentPin--)
   {
      digitalWrite(currentPin, HIGH);
      delay(timer);
      digitalWrite(currentPin, LOW);
   }
}

The code is displayed in the image below, which will be on each card, but you may want to make note of it before going on.

Question Image
Question 1 of 10

For Loops

Correct!

All flashcards in this set deal with the following code:

int timer = 200;
int currentPin;

void setup()
{
   for (currentPin = 0; currentPin < 8; currentPin++)
   {
   pinMode(currentPin, OUTPUT);
   }
}

void main()
{
   for (currentPin = 0; currentPin < 8; currentPin++)
   {
      digitalWrite(currentPin, HIGH);
      delay(timer);
      digitalWrite(currentPin, LOW);
   }
   for (currentPin = 7; currentPin >= 0; currentPin--)
   {
      digitalWrite(currentPin, HIGH);
      delay(timer);
      digitalWrite(currentPin, LOW);
   }
}

The code is displayed in the image below, which will be on each card, but you may want to make note of it before going on.

question image

Correct Answer

Got it!

 Next Question
Question 1 of 10

For Loops

Incorrect

All flashcards in this set deal with the following code:

int timer = 200;
int currentPin;

void setup()
{
   for (currentPin = 0; currentPin < 8; currentPin++)
   {
   pinMode(currentPin, OUTPUT);
   }
}

void main()
{
   for (currentPin = 0; currentPin < 8; currentPin++)
   {
      digitalWrite(currentPin, HIGH);
      delay(timer);
      digitalWrite(currentPin, LOW);
   }
   for (currentPin = 7; currentPin >= 0; currentPin--)
   {
      digitalWrite(currentPin, HIGH);
      delay(timer);
      digitalWrite(currentPin, LOW);
   }
}

The code is displayed in the image below, which will be on each card, but you may want to make note of it before going on.

question image

Your Answer

Correct Answer

Got it!

 Next Question
Question 1 of 10

For Loops

True or False: The for loop in the setup function only sets every other digital pin as an output.

Question Image
Question 1 of 10

For Loops

Correct!

True or False: The for loop in the setup function only sets every other digital pin as an output.

question image

Correct Answer

False

Explanation:

The for loop in setup assigns incremental values to currentPin and sets those pins to OUTPUT.

It starts with the value 0, then 1, 2, 3, and so on, until the value of currentPin becomes 8.  It will not execute the code when currentPin is 8, because 8 < 8 is false.  

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: The for loop in the setup function only sets every other digital pin as an output.

question image

Your Answer

Correct Answer

False

Explanation:

The for loop in setup assigns incremental values to currentPin and sets those pins to OUTPUT.

It starts with the value 0, then 1, 2, 3, and so on, until the value of currentPin becomes 8.  It will not execute the code when currentPin is 8, because 8 < 8 is false.  

 Next Question
Question 1 of 10

For Loops

True or False: The for loop in the setup function loops 7 times (i.e. the code under the for statement executes 7 times.)

Question Image
Question 1 of 10

For Loops

Correct!

True or False: The for loop in the setup function loops 7 times (i.e. the code under the for statement executes 7 times.)

question image

Correct Answer

False

Explanation:

The code under the for statement actually executes 8 times, 0, 1, 2, 3, 4, 5, 6, 7.  

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: The for loop in the setup function loops 7 times (i.e. the code under the for statement executes 7 times.)

question image

Your Answer

Correct Answer

False

Explanation:

The code under the for statement actually executes 8 times, 0, 1, 2, 3, 4, 5, 6, 7.  

 Next Question
Question 1 of 10

For Loops

True or False: The first for loop in the main function turns digital outputs 0 through 7 on and then off, one at a time.

Question Image
Question 1 of 10

For Loops

Correct!

True or False: The first for loop in the main function turns digital outputs 0 through 7 on and then off, one at a time.

question image

Correct Answer

True

Explanation:

The code within the first for loop turns on digital output currentPin, waits for timer milliseconds, then turns off digital output currentPin.  It starts with currentPin at 0 and then increments through the values, 1, 2, ..., until it gets to 8 (which it does not run the code under the for loop for as 8 < 8 is false).  

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: The first for loop in the main function turns digital outputs 0 through 7 on and then off, one at a time.

question image

Your Answer

Correct Answer

True

Explanation:

The code within the first for loop turns on digital output currentPin, waits for timer milliseconds, then turns off digital output currentPin.  It starts with currentPin at 0 and then increments through the values, 1, 2, ..., until it gets to 8 (which it does not run the code under the for loop for as 8 < 8 is false).  

 Next Question
Question 1 of 10

For Loops

True or False: We could turn every other digital output on and then off by changing currentPin++ to currentPin = currentPin + 2 in the first for loop of the main function.

Question Image
Question 1 of 10

For Loops

Correct!

True or False: We could turn every other digital output on and then off by changing currentPin++ to currentPin = currentPin + 2 in the first for loop of the main function.

question image

Correct Answer

True

Explanation:

Making this change would have currentPin cycle through 0, 2, 4, 6, and then 8 and stop looping.

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: We could turn every other digital output on and then off by changing currentPin++ to currentPin = currentPin + 2 in the first for loop of the main function.

question image

Your Answer

Correct Answer

True

Explanation:

Making this change would have currentPin cycle through 0, 2, 4, 6, and then 8 and stop looping.

 Next Question
Question 1 of 10

For Loops

True or False: To keep the digital outputs on longer, we could decrease the value of the variable timer.  

Question Image
Question 1 of 10

For Loops

Correct!

True or False: To keep the digital outputs on longer, we could decrease the value of the variable timer.  

question image

Correct Answer

False

Explanation:

To increase the time the outputs are on, you would need to increase the value of timer

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: To keep the digital outputs on longer, we could decrease the value of the variable timer.  

question image

Your Answer

Correct Answer

False

Explanation:

To increase the time the outputs are on, you would need to increase the value of timer

 Next Question
Question 1 of 10

For Loops

True or False: The second for loop in the main function turns digital outputs 0 through 7 on and then off one at a time starting with digital output 0.

Question Image
Question 1 of 10

For Loops

Correct!

True or False: The second for loop in the main function turns digital outputs 0 through 7 on and then off one at a time starting with digital output 0.

question image

Correct Answer

False

Explanation:

The second for loop starts with pin 7.  

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: The second for loop in the main function turns digital outputs 0 through 7 on and then off one at a time starting with digital output 0.

question image

Your Answer

Correct Answer

False

Explanation:

The second for loop starts with pin 7.  

 Next Question
Question 1 of 10

For Loops

If a for loop is to only execute one line of code, can we eliminate the curly brackets around the for body?

Question Image
Question 1 of 10

For Loops

Correct!

If a for loop is to only execute one line of code, can we eliminate the curly brackets around the for body?

question image

Correct Answer

Yes

Explanation:

A for loop without any curly brackets following it will execute (exactly) the next line of code each time it loops.

 Next Question
Question 1 of 10

For Loops

Incorrect

If a for loop is to only execute one line of code, can we eliminate the curly brackets around the for body?

question image

Your Answer

Correct Answer

Yes

Explanation:

A for loop without any curly brackets following it will execute (exactly) the next line of code each time it loops.

 Next Question
Question 1 of 10

For Loops

How many times would the line(s) of code below the following for loop be executed?

for (currentPin = 7; currentPin >= 0; currentPin--);

Question Image
Question 1 of 10

For Loops

Correct!

How many times would the line(s) of code below the following for loop be executed?

for (currentPin = 7; currentPin >= 0; currentPin--);

question image

Correct Answer

1

Explanation:

This for loop actually has an empty body as the ; ends it.  Therefore, the system will loop through (doing nothing) and then move onto whatever code follows, executing it as if it were not in a for loop (because it isn't).

 Next Question
Question 1 of 10

For Loops

Incorrect

How many times would the line(s) of code below the following for loop be executed?

for (currentPin = 7; currentPin >= 0; currentPin--);

question image

Your Answer

Correct Answer

1

Explanation:

This for loop actually has an empty body as the ; ends it.  Therefore, the system will loop through (doing nothing) and then move onto whatever code follows, executing it as if it were not in a for loop (because it isn't).

 Next Question
Question 1 of 10

For Loops

True or False: The conditional test of a for loop must not be true in order for the for statement to loop again. 

Question Image
Question 1 of 10

For Loops

Correct!

True or False: The conditional test of a for loop must not be true in order for the for statement to loop again. 

question image

Correct Answer

False

Explanation:

The conditional test of a for loop must be true in order for the loop to run again.

 Next Question
Question 1 of 10

For Loops

Incorrect

True or False: The conditional test of a for loop must not be true in order for the for statement to loop again. 

question image

Your Answer

Correct Answer

False

Explanation:

The conditional test of a for loop must be true in order for the loop to run again.

 Next Question
Question 1 of 10

For Loops

How many times would the body of the for loop below be executed?

for (currentPin = 0; currentPin < 0; currentPin++)

Question Image
Question 1 of 10

For Loops

Correct!

How many times would the body of the for loop below be executed?

for (currentPin = 0; currentPin < 0; currentPin++)

question image

Correct Answer

0

Explanation:

After we assign 0 to currentPin, the condition is false, so the body of this for loop will not be executed at all.  

 Finish
Question 1 of 10

For Loops

Incorrect

How many times would the body of the for loop below be executed?

for (currentPin = 0; currentPin < 0; currentPin++)

question image

Your Answer

Correct Answer

0

Explanation:

After we assign 0 to currentPin, the condition is false, so the body of this for loop will not be executed at all.  

 Finish
Question 1 of 10
For Loops

Score

You have answered 5 of 10 questions correctly.

50%

Start Over

See other flashcards and apps related to:

Question 1 of 10
Author
Published
6/2/2015
Last Updated
6/2/2015
Tags

No Comments Yet