The learner will review code and answer questions about 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.
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.
Got it!
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.
Got it!
True or False: The for loop in the setup function only sets every other digital pin as an output.
True or False: The for loop in the setup function only sets every other digital pin as an output.
False
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.
True or False: The for loop in the setup function only sets every other digital pin as an output.
False
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.
True or False: The for loop in the setup function loops 7 times (i.e. the code under the for statement executes 7 times.)
True or False: The for loop in the setup function loops 7 times (i.e. the code under the for statement executes 7 times.)
False
The code under the for statement actually executes 8 times, 0, 1, 2, 3, 4, 5, 6, 7.
True or False: The for loop in the setup function loops 7 times (i.e. the code under the for statement executes 7 times.)
False
The code under the for statement actually executes 8 times, 0, 1, 2, 3, 4, 5, 6, 7.
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.
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.
True
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).
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.
True
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).
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.
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.
True
Making this change would have currentPin cycle through 0, 2, 4, 6, and then 8 and stop looping.
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.
True
Making this change would have currentPin cycle through 0, 2, 4, 6, and then 8 and stop looping.
True or False: To keep the digital outputs on longer, we could decrease the value of the variable timer.
True or False: To keep the digital outputs on longer, we could decrease the value of the variable timer.
False
To increase the time the outputs are on, you would need to increase the value of timer.
True or False: To keep the digital outputs on longer, we could decrease the value of the variable timer.
False
To increase the time the outputs are on, you would need to increase the value of timer.
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.
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.
False
The second for loop starts with pin 7.
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.
False
The second for loop starts with pin 7.
If a for loop is to only execute one line of code, can we eliminate the curly brackets around the for body?
If a for loop is to only execute one line of code, can we eliminate the curly brackets around the for body?
Yes
A for loop without any curly brackets following it will execute (exactly) the next line of code each time it loops.
If a for loop is to only execute one line of code, can we eliminate the curly brackets around the for body?
Yes
A for loop without any curly brackets following it will execute (exactly) the next line of code each time it loops.
How many times would the line(s) of code below the following for loop be executed?
for (currentPin = 7; currentPin >= 0; currentPin--);
How many times would the line(s) of code below the following for loop be executed?
for (currentPin = 7; currentPin >= 0; currentPin--);
1
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).
How many times would the line(s) of code below the following for loop be executed?
for (currentPin = 7; currentPin >= 0; currentPin--);
1
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).
True or False: The conditional test of a for loop must not be true in order for the for statement to loop again.
True or False: The conditional test of a for loop must not be true in order for the for statement to loop again.
False
The conditional test of a for loop must be true in order for the loop to run again.
True or False: The conditional test of a for loop must not be true in order for the for statement to loop again.
False
The conditional test of a for loop must be true in order for the loop to run again.
How many times would the body of the for loop below be executed?
for (currentPin = 0; currentPin < 0; currentPin++)
How many times would the body of the for loop below be executed?
for (currentPin = 0; currentPin < 0; currentPin++)
0
After we assign 0 to currentPin, the condition is false, so the body of this for loop will not be executed at all.
How many times would the body of the for loop below be executed?
for (currentPin = 0; currentPin < 0; currentPin++)
0
After we assign 0 to currentPin, the condition is false, so the body of this for loop will not be executed at all.
You have answered 5 of 10 questions correctly.
50%