WorksheetsProgram comments, Delay and Conditional Control
Total questions: 64
Worksheet time: 32mins
What is the purpose of program comments in a code?
To make the code run faster
To document or describe important statements in a program
To increase the size of the code
To delete code blocks
Single-line comments in a program begin with a pair of ______ characters with no spaces between them.
slash (//)
asterisk (**)
hash (##)
semicolon (;;)
Which of the following is an example of a single-line comment? Select the correct answer.
/* This is a comment */
// put your main code here, to run repeatedly:
# This is a comment
There are two basic types of comments in programming: Single line and ______ comments.
Multiline
Inline
Block
Header
What is the correct way to begin and end a multiline comment in programming?
// to //
/* to */
# to #
There are spaces between the two characters pairs in a multiline comment (/* and */).
True
False
Fill in the blank: Everything which is written in between the lines of a multiline comment is treated as a ______ and is ignored by the compiler.
comment
variable
function
statement
For what purpose is a multiline comment suitable in programming?
It is suitable for documenting author name, title, and introduction information.
It is used to execute multiple lines of code simultaneously.
It is suitable for storing user input data.
It is used to display output on the screen.
Fill in the blank for the following multi-line comment field: /* * Name : _______ * Class : 1 Mutiara * Date : 15 Mei 2022 * Title: * About: */
Asri bin Muhamad Kamil
Ahmad bin Salleh
Siti Nurhaliza binti Tarudin
Mohd Faizal bin Hassan
Fill in the blank for the following multi-line comment field: /* * Name : Asri bin Muhamad Kamil * Class : _______ * Date : 15 Mei 2022 * Title: * About: */
1 Mutiara
2 Berlian
3 Zamrud
4 Delima
Fill in the blank for the following multi-line comment field: /* * Name : Asri bin Muhamad Kamil * Class : 1 Mutiara * Date : _______ * Title: * About: */
15 Mei 2022
20 April 2021
10 Jun 2023
5 Mac 2022
Fill in the blank for the following multi-line comment field: /* * Name : Asri bin Muhamad Kamil * Class : 1 Mutiara * Date : 15 Mei 2022 * Title: _______ * About: */ What is the most suitable title for the above comment field?
My Family
My School
My Hobby
My Country
Fill in the blank for the following multi-line comment field: /* * Name : Asri bin Muhamad Kamil * Class : 1 Mutiara * Date : 15 Mei 2022 * Title: * About: _______ */ What is the most appropriate word to fill in the blank? A. Student B. Teacher C. School D. Homework
Student
Teacher
School
Homework
What does the comment '// sets the LED on' describe in the code?
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
pinMode(ledPin, OUTPUT);
delay(1000);
Which cable should you use to connect the Arduino UNO board to your computer?
HDMI cable
USB cable
Ethernet cable
Power cable
Which board should you select in the Arduino IDE for this activity?
Arduino Mega
Arduino Nano
Arduino UNO
Arduino Leonardo
To choose the port for your Arduino board in the Arduino IDE, which steps should you follow?
Go to Tools > Port and select the correct port for your board.
Go to File > Preferences and select the port.
Go to Edit > Port and choose the port.
Go to Sketch > Port and select the port.
What button do you click to upload the blink program onto the Arduino UNO board?
Upload button.
Reset button.
Serial Monitor button.
Verify button.
What change can you make to the blink program as suggested in the instructions?
Increase or decrease the delay value.
Change the color of the LED.
Add more LEDs to the circuit.
Remove the microcontroller.
What are the two types of conditional control statements in Arduino C?
IF... ELSE statement and SWITCH... CASE statement
FOR... NEXT statement and WHILE... DO statement
DO... WHILE statement and REPEAT... UNTIL statement
BREAK statement and CONTINUE statement
In Arduino C, which statement is used for conditional control when you want to check multiple conditions one after another?
SWITCH... CASE
IF... ELSE
FOR loop
WHILE loop
In Arduino C, which statement is used for conditional control when you want to select one option from many possible cases?
A) IF... ELSE
B) SWITCH... CASE
C) WHILE loop
D) FOR loop
C language as well as Arduino C has a list of comparison operators available. The operators are mostly binary operators and require two operands as the following: Which comparison operator in C is used to check if two values are equal?
==
!=
<
>
C language as well as Arduino C has a list of comparison operators available. The operators are mostly binary operators and require two operands as the following: Which comparison operator in C is used to check if two values are not equal?
==
!=
<
>
C language as well as Arduino C has a list of comparison operators available. The operators are mostly binary operators and require two operands as the following: Which comparison operator in C is used to check if one value is less than another?
==
!=
<
>
C language as well as Arduino C has a list of comparison operators available. The operators are mostly binary operators and require two operands as the following: Which comparison operator in C is used to check if one value is greater than another?
==
!=
<
>
Fill in the blank: The operator for 'less than or equal to' in C is _______.
<=
=<
>=
<<
Fill in the blank: The operator for 'greater than or equal to' in C is _______.
>=
=>
>==
=<
In a computer program, in what order are statements processed if no IF... ELSE statement is used?
Random order
Top to bottom, one after another
Bottom to top
Only the first statement is processed
What is the purpose of using an IF... ELSE statement in a program?
To repeat statements
To change the output conditions based on changing the input conditions
To stop the program
To skip all statements
Fill in the blank: An IF... ELSE statement is used to change the output conditions based on changing the ______ conditions.
input
output
loop
variable
What is the correct syntax for an IF statement in C programming?
A) if [expression] { }
B) if (expression) { }
C) if expression { }
D) if: (expression) { }
In an Arduino C sketch, where does the program start processing statements?
loop()
main()
setup()
start()
What does the 'else' block do in this code?
Performs the first statement block if logic true
Performs the second statement block otherwise
Evaluates the expression to logic true
None of the above
What happens if the expression does NOT evaluate to logic true in this 'if only' statement?
Nothing happens; the statement block is not executed.
The statement block is executed regardless.
An error is thrown by the compiler.
The program terminates immediately.
According to the passage, Arduino C allows computers to nest if statements within an if so that we can have more than two conditions. Which keyword is used for this purpose?
A) else
B) if
C) else if
D) switch
The colour sensor could detect various colours such as Red, Blue, Green, and Yellow which associates with ________ action.
different
same
random
single
In the given code structure: { // perform this Nth statement block if logic true } else { // perform this statement block otherwise } What does the 'else' block execute?
If the logic is true
If the logic is false
Always
Never
Fill in the blank: In the given code structure, the statement block inside the 'if' is executed if the logic is _____
true
false
undefined
null
What is the SWITCH()... CASE statement an alternative to?
WHILE loop
IF()... ELSE
FOR loop
DO... WHILE
Fill in the blank: The SWITCH()... CASE statement is more suitable in handling condition with more than ____ cases.
two
one
three
four
Which of the following best describes the purpose of the SWITCH()... CASE statement?
To repeat a block of code multiple times
To change the output conditions based on changing the input conditions
To handle errors in a program
To define variables
In the SWITCH()... CASE syntax, what is executed if the expression doesn't have a matching case?
The first case
The last case
The default case
None of the above
According to the passage, what happens if a value for expression does not match any case value in a switch statement?
The program throws an error
The default statement block is executed
The first case statement block is executed
The switch statement is skipped
Based on the passage, is the default case in a switch statement mandatory?
True
False
Fill in the blank: The switch expression must evaluate to an ______ data type. It cannot be a floating-point type (float or double) nor can it be a reference data type (e.g. String).
integral
floating-point
reference
character
Objective: This activity is to use IF ()… ELSE statement to implement a conditional control in our Arduino Program. We are going to light the LED when the pushbutton is push and OFF the LED when the pushbutton is not pressed. Which statement is used in the Arduino program to check if the pushbutton is pressed?
if (buttonState == HIGH)
if (ledPin == LOW)
if (buttonPush == LOW)
if (buttonState == LOW)
Fill in the blank: The LED will turn ON when the pushbutton is _________.
pressed
released
broken
disconnected
What is the purpose of the digitalWrite(ledPin, LOW) statement in the Arduino program?
To turn off the LED connected to ledPin.
To increase the brightness of the LED.
To blink the LED rapidly.
To turn on the LED connected to ledPin.
Objective: This activity is to use IF ()… ELSE statement to implement a conditional control in our Arduino Program. We are going to light the LED when the pushbutton is push and OFF the LED when the pushbutton is not pressed.
True
False
What is the main purpose of using the SWITCH()... CASE statement in this Arduino activity?
To control multiple LEDs
To control 1 LED using 1 button
To read temperature
To display text on screen
Which Arduino function is used to set the mode of a pin as input or output?
digitalRead()
pinMode()
digitalWrite()
switch()
Fill in the blank: The variable that stores the state of the button is called _______.
buttonState
buttonValue
stateButton
btnStatus
What happens to the LED when the button is pressed according to the code provided?
The LED turns on.
The LED turns off.
The LED blinks rapidly.
The LED changes color.
Describe the steps to upload a program onto the Arduino Uno and test it using the button switch.
Connect the Arduino Uno to your computer, open the Arduino IDE, write or load the program, select the correct board and port, upload the program, and test the button switch.
Connect the Arduino Uno to a battery, write the program on paper, and press the button switch to test.
Upload the program to the Arduino Uno using a mobile app, then test the button switch without connecting to a computer.
Write the program, save it on a USB drive, and insert the drive into the Arduino Uno to test the button switch.
Write the 2 types of comments. (1) Single line: ____________
Single line comment
Multi line comment
Block comment
Inline comment
Write the 2 types of comments. (2) Multiline: ____________
Multiline comment
Single-line comment
Inline comment
Block comment
Identify the part of the code indicated by the first arrow in the following code:
Function name
Variable name
Return type
Parameter list
Identify the part of the code indicated by the second arrow in the following code:
Argument or parameter
Function name
Return value
Operator
Fill in the blank for IF... ELSE: ____________
Conditional statement
Loop statement
Assignment statement
Function call
Fill in the blank for SWITCH ... CASE: ____________
Selection statement
Iteration statement
Assignment statement
Declaration statement
Objective: To setup built in LED to blink. To create, compile and upload our first Arduino sketch. Which code will make the built-in LED on an Arduino board blink?
void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }
void setup() { pinMode(LED_BUILTIN, INPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }
void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, LOW); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }
void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(5000); digitalWrite(LED_BUILTIN, HIGH); delay(5000); }
Objective: This activity is to use IF ()… ELSE statement to implement a conditional control in our Arduino Program. We are going to light the LED when the pushbutton is push and OFF the LED when the pushbutton is not pressed. Which of the following Arduino code snippets correctly implements the objective described above?
if (digitalRead(buttonPin) == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }
if (digitalRead(buttonPin) == LOW) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }
digitalWrite(ledPin, HIGH);
if (digitalRead(ledPin) == HIGH) { digitalWrite(buttonPin, HIGH); } else { digitalWrite(buttonPin, LOW); }
Objective: This activity is going to use SWITCH()… CASE statement to control 1 LED using 1 button. Once the button is pressed, LED will be turned ON. Which statement structure should be used to control the LED with a button press in this activity?
SWITCH()… CASE
IF… ELSE
FOR loop
WHILE loop
