ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos


Computer Science Videos 112 videos

Computer Science: Setting Up Your Environment
19 Views

Just as you move your furniture into a new house before spending the night, you’ve got to spend a little time setting up your environment when yo...

Computer Science: Doubles and Ints
17 Views

Doubles and ints. At first glance, it may look like this video will be about baseball and football statistics. But they're actually computer scienc...

AP Computer Science 1.1 Classes and Objects
468 Views

AP Computer Science: Classes and Objects Drill 1, Problem 1. Which of the following is a correct {/* Implementation */} for the isInsect method?

See All

AP Computer Science 2.5 Review of the Basics 4 Views


Share It!


Description:

Anyone know what the value of "q" is? We took it into a pawn shop, but the woman just looked at us funny.

Language:
English Language

Transcript

00:04

And here's your shmoop du jour brought to you by devious spaghetti [Man smirking near spaghetti]

00:07

companies confusing coders since the beginning of time... Consider the

00:11

following code segment......what is the value of Q after the code has run to

00:18

completion and here are the potential answers.... okay, here we go well this

00:24

requires us to track the value of Q as we traverse the loop and here's our [formula for value of q circled]

00:29

handy counter let's start tracing this mess of spaghetti code and pass the

00:34

butter alright so if we look at the first if loop notice that it's testing

00:37

whether I is odd so for every odd value between 0 and 30 Q will increment go up

00:44

there are 15 odd values between 0 and 30 and since Q is already one well we know [odd values circled]

00:49

in the end that it must be at least 16 let's take a look at the second

00:53

if loop, it tests whether q is equal to some number / q well in this case some

00:58

number is 0 is 0 / 1 equal to 1 well no, it's equal to 0 though in the second

01:04

iteration for the for loop the second if loops doesn't execute it just kind of

01:08

sits there looking dumb.....all right well in fact we can [Man sitting looking at the ocean]

01:13

see that the only time the second if loop executes is when I equals 2 so in

01:19

this case Q also equals 2 and 2 times 2 over 2 definitely equals 2 so wow that's

01:24

a lot of two's from there however Q will always be greater than two times I thus

01:30

the if loop will never execute again this means that we have Q at a total of [hand crosses line through if loop]

01:36

17 so the answer is C well done that's using your noodle [Boy sat at a table with plate of noodles]

Related Videos

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism
204 Views

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...

AP Computer Science 4.2 Standard Algorithms
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?