Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Program comments, Delay and Conditional Control

Total questions: 64

Worksheet time: 32mins

Name
Class
Date
1.

What is the purpose of program comments in a code?

a)

To make the code run faster

b)

To document or describe important statements in a program

c)

To increase the size of the code

d)

To delete code blocks

2.

Single-line comments in a program begin with a pair of ______ characters with no spaces between them.

a)

slash (//)

b)

asterisk (**)

c)

hash (##)

d)

semicolon (;;)

3.

Which of the following is an example of a single-line comment? Select the correct answer.

a)

/* This is a comment */

b)

// put your main code here, to run repeatedly:

c)

d)

# This is a comment

4.

There are two basic types of comments in programming: Single line and ______ comments.

a)

Multiline

b)

Inline

c)

Block

d)

Header

5.

What is the correct way to begin and end a multiline comment in programming?

a)

// to //

b)

/* to */

c)

d)

# to #

6.

There are spaces between the two characters pairs in a multiline comment (/* and */).

a)

True

b)

False

7.

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.

a)

comment

b)

variable

c)

function

d)

statement

8.

For what purpose is a multiline comment suitable in programming?

a)

It is suitable for documenting author name, title, and introduction information.

b)

It is used to execute multiple lines of code simultaneously.

c)

It is suitable for storing user input data.

d)

It is used to display output on the screen.

9.

Fill in the blank for the following multi-line comment field: /* * Name : _______ * Class : 1 Mutiara * Date : 15 Mei 2022 * Title: * About: */

a)

Asri bin Muhamad Kamil

b)

Ahmad bin Salleh

c)

Siti Nurhaliza binti Tarudin

d)

Mohd Faizal bin Hassan

10.

Fill in the blank for the following multi-line comment field: /* * Name : Asri bin Muhamad Kamil * Class : _______ * Date : 15 Mei 2022 * Title: * About: */

a)

1 Mutiara

b)

2 Berlian

c)

3 Zamrud

d)

4 Delima

11.

Fill in the blank for the following multi-line comment field: /* * Name : Asri bin Muhamad Kamil * Class : 1 Mutiara * Date : _______ * Title: * About: */

a)

15 Mei 2022

b)

20 April 2021

c)

10 Jun 2023

d)

5 Mac 2022

12.

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?

a)

My Family

b)

My School

c)

My Hobby

d)

My Country

13.

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

a)

Student

b)

Teacher

c)

School

d)

Homework

14.

What does the comment '// sets the LED on' describe in the code?

a)

digitalWrite(ledPin, HIGH);

b)

digitalWrite(ledPin, LOW);

c)

pinMode(ledPin, OUTPUT);

d)

delay(1000);

15.

Which cable should you use to connect the Arduino UNO board to your computer?

a)

HDMI cable

b)

USB cable

c)

Ethernet cable

d)

Power cable

16.

Which board should you select in the Arduino IDE for this activity?

a)

Arduino Mega

b)

Arduino Nano

c)

Arduino UNO

d)

Arduino Leonardo

17.

To choose the port for your Arduino board in the Arduino IDE, which steps should you follow?

a)

Go to Tools > Port and select the correct port for your board.

b)

Go to File > Preferences and select the port.

c)

Go to Edit > Port and choose the port.

d)

Go to Sketch > Port and select the port.

18.

What button do you click to upload the blink program onto the Arduino UNO board?

a)

Upload button.

b)

Reset button.

c)

Serial Monitor button.

d)

Verify button.

19.

What change can you make to the blink program as suggested in the instructions?

a)

Increase or decrease the delay value.

b)

Change the color of the LED.

c)

Add more LEDs to the circuit.

d)

Remove the microcontroller.

20.

What are the two types of conditional control statements in Arduino C?

a)

IF... ELSE statement and SWITCH... CASE statement

b)

FOR... NEXT statement and WHILE... DO statement

c)

DO... WHILE statement and REPEAT... UNTIL statement

d)

BREAK statement and CONTINUE statement

21.

In Arduino C, which statement is used for conditional control when you want to check multiple conditions one after another?

a)

SWITCH... CASE

b)

IF... ELSE

c)

FOR loop

d)

WHILE loop

22.

In Arduino C, which statement is used for conditional control when you want to select one option from many possible cases?

a)

A) IF... ELSE

b)

B) SWITCH... CASE

c)

C) WHILE loop

d)

D) FOR loop

23.

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?

a)

==

b)

!=

c)

<

d)

>

24.

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?

a)

==

b)

!=

c)

<

d)

>

25.

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?

a)

==

b)

!=

c)

<

d)

>

26.

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?

a)

==

b)

!=

c)

<

d)

>

27.

Fill in the blank: The operator for 'less than or equal to' in C is _______.

a)

<=

b)

=<

c)

>=

d)

<<

28.

Fill in the blank: The operator for 'greater than or equal to' in C is _______.

a)

>=

b)

=>

c)

>==

d)

=<

29.

In a computer program, in what order are statements processed if no IF... ELSE statement is used?

a)

Random order

b)

Top to bottom, one after another

c)

Bottom to top

d)

Only the first statement is processed

30.

What is the purpose of using an IF... ELSE statement in a program?

a)

To repeat statements

b)

To change the output conditions based on changing the input conditions

c)

To stop the program

d)

To skip all statements

31.

Fill in the blank: An IF... ELSE statement is used to change the output conditions based on changing the ______ conditions.

a)

input

b)

output

c)

loop

d)

variable

32.

What is the correct syntax for an IF statement in C programming?

a)

A) if [expression] { }

b)

B) if (expression) { }

c)

C) if expression { }

d)

D) if: (expression) { }

33.

In an Arduino C sketch, where does the program start processing statements?

a)

loop()

b)

main()

c)

setup()

d)

start()

34.

What does the 'else' block do in this code?

a)

Performs the first statement block if logic true

b)

Performs the second statement block otherwise

c)

Evaluates the expression to logic true

d)

None of the above

35.

What happens if the expression does NOT evaluate to logic true in this 'if only' statement?

a)

Nothing happens; the statement block is not executed.

b)

The statement block is executed regardless.

c)

An error is thrown by the compiler.

d)

The program terminates immediately.

36.

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)

A) else

b)

B) if

c)

C) else if

d)

D) switch

37.

The colour sensor could detect various colours such as Red, Blue, Green, and Yellow which associates with ________ action.

a)

different

b)

same

c)

random

d)

single

38.

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?

a)

If the logic is true

b)

If the logic is false

c)

Always

d)

Never

39.

Fill in the blank: In the given code structure, the statement block inside the 'if' is executed if the logic is _____

a)

true

b)

false

c)

undefined

d)

null

40.

What is the SWITCH()... CASE statement an alternative to?

a)

WHILE loop

b)

IF()... ELSE

c)

FOR loop

d)

DO... WHILE

41.

Fill in the blank: The SWITCH()... CASE statement is more suitable in handling condition with more than ____ cases.

a)

two

b)

one

c)

three

d)

four

42.

Which of the following best describes the purpose of the SWITCH()... CASE statement?

a)

To repeat a block of code multiple times

b)

To change the output conditions based on changing the input conditions

c)

To handle errors in a program

d)

To define variables

43.

In the SWITCH()... CASE syntax, what is executed if the expression doesn't have a matching case?

a)

The first case

b)

The last case

c)

The default case

d)

None of the above

44.

According to the passage, what happens if a value for expression does not match any case value in a switch statement?

a)

The program throws an error

b)

The default statement block is executed

c)

The first case statement block is executed

d)

The switch statement is skipped

45.

Based on the passage, is the default case in a switch statement mandatory?

a)

True

b)

False

46.

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).

a)

integral

b)

floating-point

c)

reference

d)

character

47.

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?

a)

if (buttonState == HIGH)

b)

if (ledPin == LOW)

c)

if (buttonPush == LOW)

d)

if (buttonState == LOW)

48.

Fill in the blank: The LED will turn ON when the pushbutton is _________.

a)

pressed

b)

released

c)

broken

d)

disconnected

49.

What is the purpose of the digitalWrite(ledPin, LOW) statement in the Arduino program?

a)

To turn off the LED connected to ledPin.

b)

To increase the brightness of the LED.

c)

To blink the LED rapidly.

d)

To turn on the LED connected to ledPin.

50.

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.

a)

True

b)

False

51.

What is the main purpose of using the SWITCH()... CASE statement in this Arduino activity?

a)

To control multiple LEDs

b)

To control 1 LED using 1 button

c)

To read temperature

d)

To display text on screen

52.

Which Arduino function is used to set the mode of a pin as input or output?

a)

digitalRead()

b)

pinMode()

c)

digitalWrite()

d)

switch()

53.

Fill in the blank: The variable that stores the state of the button is called _______.

a)

buttonState

b)

buttonValue

c)

stateButton

d)

btnStatus

54.

What happens to the LED when the button is pressed according to the code provided?

a)

The LED turns on.

b)

The LED turns off.

c)

The LED blinks rapidly.

d)

The LED changes color.

55.

Describe the steps to upload a program onto the Arduino Uno and test it using the button switch.

a)

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.

b)

Connect the Arduino Uno to a battery, write the program on paper, and press the button switch to test.

c)

Upload the program to the Arduino Uno using a mobile app, then test the button switch without connecting to a computer.

d)

Write the program, save it on a USB drive, and insert the drive into the Arduino Uno to test the button switch.

56.

Write the 2 types of comments. (1) Single line: ____________

a)

Single line comment

b)

Multi line comment

c)

Block comment

d)

Inline comment

57.

Write the 2 types of comments. (2) Multiline: ____________

a)

Multiline comment

b)

Single-line comment

c)

Inline comment

d)

Block comment

58.

Identify the part of the code indicated by the first arrow in the following code:

a)

Function name

b)

Variable name

c)

Return type

d)

Parameter list

59.

Identify the part of the code indicated by the second arrow in the following code:

a)

Argument or parameter

b)

Function name

c)

Return value

d)

Operator

60.

Fill in the blank for IF... ELSE: ____________

a)

Conditional statement

b)

Loop statement

c)

Assignment statement

d)

Function call

61.

Fill in the blank for SWITCH ... CASE: ____________

a)

Selection statement

b)

Iteration statement

c)

Assignment statement

d)

Declaration statement

62.

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?

a)

void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }

b)

void setup() { pinMode(LED_BUILTIN, INPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }

c)

void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, LOW); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); }

d)

void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(5000); digitalWrite(LED_BUILTIN, HIGH); delay(5000); }

63.

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?

a)

if (digitalRead(buttonPin) == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }

b)

if (digitalRead(buttonPin) == LOW) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }

c)

digitalWrite(ledPin, HIGH);

d)

if (digitalRead(ledPin) == HIGH) { digitalWrite(buttonPin, HIGH); } else { digitalWrite(buttonPin, LOW); }

64.

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?

a)

SWITCH()… CASE

b)

IF… ELSE

c)

FOR loop

d)

WHILE loop