The learner will review code and answer questions about arrays and for loops.

Arrays

All the flashcards in this set deal with the following code:

int timer = 200;
int digoutPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
int adifferentArray[] = {2, 5, 3, 8, 9};
char thirdArray[30];
int digoutCount = 8;

void setup()
{
   for (int PinNum = 0; PinNum < digoutCount; PinNum++)
      pinMode(digoutPins[PinNum], OUTPUT);
}

void main()
{
   for (int PinNum = 0; PinNum < digoutCount; PinNum++)
   {
      digitalWrite(digoutPins[PinNum], HIGH);
      delay(timer);
      digitalWrite(digoutPins[PinNum], LOW);
      delay(timer);
   }
   for (int PinNum = digoutCount - 1; PinNum >- 0; PinNum--)
   {
      digitalWrite(digoutPins[PinNum], HIGH);
      delay(timer);
      digitalWrite(digoutPins[PinNum], LOW);
      delay(timer);
   }
}

This 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

Arrays

Correct!

All the flashcards in this set deal with the following code:

int timer = 200;
int digoutPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
int adifferentArray[] = {2, 5, 3, 8, 9};
char thirdArray[30];
int digoutCount = 8;

void setup()
{
   for (int PinNum = 0; PinNum < digoutCount; PinNum++)
      pinMode(digoutPins[PinNum], OUTPUT);
}

void main()
{
   for (int PinNum = 0; PinNum < digoutCount; PinNum++)
   {
      digitalWrite(digoutPins[PinNum], HIGH);
      delay(timer);
      digitalWrite(digoutPins[PinNum], LOW);
      delay(timer);
   }
   for (int PinNum = digoutCount - 1; PinNum >- 0; PinNum--)
   {
      digitalWrite(digoutPins[PinNum], HIGH);
      delay(timer);
      digitalWrite(digoutPins[PinNum], LOW);
      delay(timer);
   }
}

This 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

Arrays

Incorrect

All the flashcards in this set deal with the following code:

int timer = 200;
int digoutPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
int adifferentArray[] = {2, 5, 3, 8, 9};
char thirdArray[30];
int digoutCount = 8;

void setup()
{
   for (int PinNum = 0; PinNum < digoutCount; PinNum++)
      pinMode(digoutPins[PinNum], OUTPUT);
}

void main()
{
   for (int PinNum = 0; PinNum < digoutCount; PinNum++)
   {
      digitalWrite(digoutPins[PinNum], HIGH);
      delay(timer);
      digitalWrite(digoutPins[PinNum], LOW);
      delay(timer);
   }
   for (int PinNum = digoutCount - 1; PinNum >- 0; PinNum--)
   {
      digitalWrite(digoutPins[PinNum], HIGH);
      delay(timer);
      digitalWrite(digoutPins[PinNum], LOW);
      delay(timer);
   }
}

This 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

Arrays

In the for loop within the setup function, PinNum has what value at the end of the third loop iteration?

Question Image
Question 1 of 10

Arrays

Correct!

In the for loop within the setup function, PinNum has what value at the end of the third loop iteration?

question image

Correct Answer

2

Explanation:

PinNum starts that loop with a value of 0 and it is increased by one each time the loop ends.  So for the first loop it is 0, for the second loop it is 1, and for the third loop it is 2.  (At the beginning of the fourth loop it is incremented to three.)

 Next Question
Question 1 of 10

Arrays

Incorrect

In the for loop within the setup function, PinNum has what value at the end of the third loop iteration?

question image

Your Answer

Correct Answer

2

Explanation:

PinNum starts that loop with a value of 0 and it is increased by one each time the loop ends.  So for the first loop it is 0, for the second loop it is 1, and for the third loop it is 2.  (At the beginning of the fourth loop it is incremented to three.)

 Next Question
Question 1 of 10

Arrays

True or False: Digital pins 0 through 8 are set up as outputs.

Question Image
Question 1 of 10

Arrays

Correct!

True or False: Digital pins 0 through 8 are set up as outputs.

question image

Correct Answer

False

Explanation:

Only pins 0 through 7 are set as outputs, the for loop in setup iterates PinNum from 0 to 7 (when it reaches 8 it stops as 8 < 8 is false).  So only the pins in the 0 through 7 places in the digoutPins array are set to OUTPUT.  Those pin values are 0 through 7.

 Next Question
Question 1 of 10

Arrays

Incorrect

True or False: Digital pins 0 through 8 are set up as outputs.

question image

Your Answer

Correct Answer

False

Explanation:

Only pins 0 through 7 are set as outputs, the for loop in setup iterates PinNum from 0 to 7 (when it reaches 8 it stops as 8 < 8 is false).  So only the pins in the 0 through 7 places in the digoutPins array are set to OUTPUT.  Those pin values are 0 through 7.

 Next Question
Question 1 of 10

Arrays

What is the value of the fourth element of the digoutPins array?

Question Image
Question 1 of 10

Arrays

Correct!

What is the value of the fourth element of the digoutPins array?

question image

Correct Answer

3

Explanation:

The digoutPins array is {0, 1, 2, 3, 4, 5, 6, 7}.  Therefore, the fourth element is 3.

 Next Question
Question 1 of 10

Arrays

Incorrect

What is the value of the fourth element of the digoutPins array?

question image

Your Answer

Correct Answer

3

Explanation:

The digoutPins array is {0, 1, 2, 3, 4, 5, 6, 7}.  Therefore, the fourth element is 3.

 Next Question
Question 1 of 10

Arrays

True or False: In the first for loop in the main section, PinNum varies from 0 to 8 inclusive and the digital pins 0 through 7 are written to.

Question Image
Question 1 of 10

Arrays

Correct!

True or False: In the first for loop in the main section, PinNum varies from 0 to 8 inclusive and the digital pins 0 through 7 are written to.

question image

Correct Answer

True

Explanation:

Initially PinNum is 0, and it is incremented until PinNum < digoutCount is false, which happens when PinNum is 8 (since 8 < 8 is false).  For each value of PinNum in 0, 1, 2, ..., 7, we perform the digitalWrite command on digoutPins[PinNum].  As digoutPins[0] = 0, digoutPins[1] = 1, ..., digoutPins[7] = 7, we do write to each of the pins 0 through 7 in this for loop.

 Next Question
Question 1 of 10

Arrays

Incorrect

True or False: In the first for loop in the main section, PinNum varies from 0 to 8 inclusive and the digital pins 0 through 7 are written to.

question image

Your Answer

Correct Answer

True

Explanation:

Initially PinNum is 0, and it is incremented until PinNum < digoutCount is false, which happens when PinNum is 8 (since 8 < 8 is false).  For each value of PinNum in 0, 1, 2, ..., 7, we perform the digitalWrite command on digoutPins[PinNum].  As digoutPins[0] = 0, digoutPins[1] = 1, ..., digoutPins[7] = 7, we do write to each of the pins 0 through 7 in this for loop.

 Next Question
Question 1 of 10

Arrays

The array values must start with the number 0.

Question Image
Question 1 of 10

Arrays

Correct!

The array values must start with the number 0.

question image

Correct Answer

False

Explanation:

The index of the first item in an array is always 0, but the values of the array can be any value (that matches the array's variable type).

 Next Question
Question 1 of 10

Arrays

Incorrect

The array values must start with the number 0.

question image

Your Answer

Correct Answer

False

Explanation:

The index of the first item in an array is always 0, but the values of the array can be any value (that matches the array's variable type).

 Next Question
Question 1 of 10

Arrays

What is the value of the fourth element of the adifferentArray array?

Question Image
Question 1 of 10

Arrays

Correct!

What is the value of the fourth element of the adifferentArray array?

question image

Correct Answer

8

Explanation:

adifferentArray has values {2, 5, 3, 8, 9} so the value of the fourth element is 8.

 Next Question
Question 1 of 10

Arrays

Incorrect

What is the value of the fourth element of the adifferentArray array?

question image

Your Answer

Correct Answer

8

Explanation:

adifferentArray has values {2, 5, 3, 8, 9} so the value of the fourth element is 8.

 Next Question
Question 1 of 10

Arrays

True or False: The second element of the digoutPins array can be accessed as digoutPins[2].

Question Image
Question 1 of 10

Arrays

Correct!

True or False: The second element of the digoutPins array can be accessed as digoutPins[2].

question image

Correct Answer

False

Explanation:

digoutPins[2] will give the value of the third element of the digoutPins array since the index for an array starts at 0.

 Next Question
Question 1 of 10

Arrays

Incorrect

True or False: The second element of the digoutPins array can be accessed as digoutPins[2].

question image

Your Answer

Correct Answer

False

Explanation:

digoutPins[2] will give the value of the third element of the digoutPins array since the index for an array starts at 0.

 Next Question
Question 1 of 10

Arrays

True or False: The thirdArray array has 30 elements.

Question Image
Question 1 of 10

Arrays

Correct!

True or False: The thirdArray array has 30 elements.

question image

Correct Answer

True

Explanation:

When it is initialized in the row char thirdArray[30]; it is set to have 30 elements.

 Next Question
Question 1 of 10

Arrays

Incorrect

True or False: The thirdArray array has 30 elements.

question image

Your Answer

Correct Answer

True

Explanation:

When it is initialized in the row char thirdArray[30]; it is set to have 30 elements.

 Next Question
Question 1 of 10

Arrays

What are the indexes of the elements in thirdArray?

Question Image
Question 1 of 10

Arrays

Correct!

What are the indexes of the elements in thirdArray?

question image

Correct Answer

0 - 29

Explanation:

Since thirdArray has 30 elements and the index of an array starts at 0, the indexes of the elements in thirdArray are 0, 1, 2, ..., 28, 29.

 Next Question
Question 1 of 10

Arrays

Incorrect

What are the indexes of the elements in thirdArray?

question image

Your Answer

Correct Answer

0 - 29

Explanation:

Since thirdArray has 30 elements and the index of an array starts at 0, the indexes of the elements in thirdArray are 0, 1, 2, ..., 28, 29.

 Next Question
Question 1 of 10

Arrays

Question 1 of 10

Arrays

Correct!

What is the correct way to assign a value to an element of thirdArray?

question image

Correct Answer

thirdArray[5] = 'I';

Explanation:

We can assign values to elements of an array that has been initialized by using the assign operation, namely =, by referencing the index of the element we want to change like arrayname[index].  Of the given choices, only one of them has a valid index, namely thirdArray[5] = 'I';

 Finish
Question 1 of 10

Arrays

Incorrect

What is the correct way to assign a value to an element of thirdArray?

question image

Your Answer

Correct Answer

thirdArray[5] = 'I';

Explanation:

We can assign values to elements of an array that has been initialized by using the assign operation, namely =, by referencing the index of the element we want to change like arrayname[index].  Of the given choices, only one of them has a valid index, namely thirdArray[5] = 'I';

 Finish
Question 1 of 10
Arrays

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