A lot of students, when they’re first learning to program, are surprised when they’re code doesn’t do what they want. We are going to explore why that is .
Newby programmer trying to write
“hey as long as these two things are false”…do some stuff
hmm… how do we write that. It might actually suprise you. First let’s look at a specific example (that I am taking from a new lesson that we aded Penjee’s and/or logic unit)
Consider the following penjee assignment.
You have Pengun starting on the very top left (Figure 1 above) and you want to write a loop that ends at the fish in column 5 (Figure 2 below)
When your code is run, it should cause the penguin to do the animation below in figure 3:
Here’s the for what we want to write.
1 2 3 4 |
begin loop : while there's no fish here and while there's no fish ahead waddle end loop |
The big question that most new programmers can’t answer is :
Do we write the code below :
OR
Or are they the same
Well, it turns out that they are the same thing and that only one of them works at all !
It turns out that the first code set (Figure 4) is the one that correctly says ” Hey as long as 2 things are not true”