Font size
Worksheetswhile loop and logical operators
Total questions: 20
Worksheet time: 20mins
Base on the image, what type of codes is used?
Logical AND operator
Logical NOT operator
While loop with an inner while loop
Logical OR operator
While loop nested in for a loop
What is a Boolean?
A value that can be true or false
A value that can only be true or false
A value which can only be true
all of the above
AND (&&) statements are only true if...
One of more conditions are true
Two conditions are true
All conditions are false
Which of the following is NOT a logical operator
And
If
Not
Or
NOT (!) operator results in true if ...
If the value of the condition is true
If the value of the condition is false
If the value for the condition is neither true nor false
OR (II) results in true if ...
Both conditions are true
Both conditions are false
One or more conditions are true
One or both conditions are true
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
}
You are promoted
You are promoted to grade 10
You are promoted
You are promoted to grade 10
no result
Base on the image, what type of codes is used?
Logical AND operator
Logical NOT operator
While loop with an inner while loop
Logical OR operator
While loop nested in for a loop
Which of the following statements is true about the following loop?
While !isOnGem{
moveForward()
}
It will move forward 5 times then it will stop
It will move forward as long as there is a gem on the tile
It will move forward exactly 20 times then it will stop
It will move forward as long as there is no gem on the tile
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
I only
II only
I and II only
II and III only
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?
In the code provided. What would best define the second "while" in the sequence?
layered loop
nested loop
labeled loop
function loop
Which of the following is a correct example of a while loop?
for i in 1…4 {
turnLeft()
moveForward()
toggleSwitch()
}
while isOnClosedSwitch {
toggleSwitch()
turnLeft()
moveForward()
}
while i in 1…4 {
toggleSwitch()
turnLeft()
moveForward()
}
if isOnClosedSwitch {
toggleSwitch()
turnLeft()
moveForward()
}
Which of the following is a correct example of using a NOT operator?
if isongem || isonswitch {
collectgem( )
toggleSwitch( )
}
if !isongem {
toggleSwitch( )
}
if isongem !! isblocked {
collectgem( )
}
if i in 1. . . 4 {
!collectgem( )
}
The ____________ combines two conditions and runs the code if at least one is true.
logical NOT operator
logical OR operator
logical AND operator
none of the above
What is the difference between && and || ?
&& is even
|| is true
&& is false
non of the above
