wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

while loop and logical operators

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.
What is this operator? &&
a)
and
b)
or
c)
Remainder or mod
d)
Multiplication
2.
What is this operator? ||
a)
and
b)
or
c)
Remainder or mod
d)
Division
3.
What is this operator? !
a)
and
b)
or
c)
not
d)
equal to
4.

Base on the image, what type of codes is used?

a)

Logical AND operator

b)

Logical NOT operator

c)

While loop with an inner while loop

d)

Logical OR operator

e)

While loop nested in for a loop

5.

What is a Boolean?

a)

A value that can be true or false

b)

A value that can only be true or false

c)

A value which can only be true

d)

all of the above

6.

AND (&&) statements are only true if...

a)

One of more conditions are true

b)

Two conditions are true

c)

All conditions are false

7.

Which of the following is NOT a logical operator

a)

And

b)

If

c)

Not

d)

Or

8.

NOT (!) operator results in true if ...

a)

If the value of the condition is true

b)

If the value of the condition is false

c)

If the value for the condition is neither true nor false

9.

OR (II) results in true if ...

a)

Both conditions are true

b)

Both conditions are false

c)

One or more conditions are true

d)

One or both conditions are true

10.

What would be the result of the code below given that grade 10 and mark 75?


If grade = 9 && mark >=60 {

You are promoted to grade 10

}

Else if grade = 10 or mark >=60 {

You are promoted

}

a)

You are promoted

b)

You are promoted to grade 10

You are promoted

c)

You are promoted to grade 10

d)

no result

11.

Base on the image, what type of codes is used?

a)

Logical AND operator

b)

Logical NOT operator

c)

While loop with an inner while loop

d)

Logical OR operator

e)

While loop nested in for a loop

12.

Which of the following statements is true about the following loop?


While !isOnGem{

moveForward()

}

a)

It will move forward 5 times then it will stop

b)

It will move forward as long as there is a gem on the tile

c)

It will move forward exactly 20 times then it will stop


d)

It will move forward as long as there is no gem on the tile

13.

Which of the following cases will cause the execution of the collectGem() command?


if isOnGem && !isBlocked {

turnLeft()

moveForward()

} else {

collectGem()

}


I. The tile is blocked

II. The character is not on a gem

III. The character is on gem and the tile is not blocked

a)

I only

b)

II only

c)

I and II only

d)

II and III only

14.

Which of the following options would be the best solution for this challenge if the switches were randomly closed or opened each time the code was run?

a)
b)
c)
d)
15.

In the code provided. What would best define the second "while" in the sequence?

a)

layered loop

b)

nested loop

c)

labeled loop

d)

function loop

16.

Which of the following is a correct example of a while loop?

a)

for i in 1…4 {

turnLeft()

moveForward()

toggleSwitch()

}

b)

while isOnClosedSwitch {

toggleSwitch()

turnLeft()

moveForward()

}

c)

while i in 1…4 {

toggleSwitch()

turnLeft()

moveForward()

}

d)

if isOnClosedSwitch {

toggleSwitch()

turnLeft()

moveForward()

}

17.

Which of the following is a correct example of using a NOT operator?

a)

if isongem || isonswitch {

collectgem( )

toggleSwitch( )

}

b)

if !isongem {

toggleSwitch( )

}

c)

if isongem !! isblocked {

collectgem( )

}

d)

if i in 1. . . 4 {

!collectgem( )

}

18.

The ____________ combines two conditions and runs the code if at least one is true.

a)

logical NOT operator

b)

logical OR operator

c)

logical AND operator

d)

none of the above

19.

What is the difference between && and || ?

a)

&& is even

b)

|| is true

c)

&& is false

d)

non of the above

20.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE