Google Groups Home
Help | Sign in
example of a logic bug using pseudocode
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
popeyerayaz  
View profile
 More options Jul 22, 12:32 am
From: popeyerayaz <popeyera...@gmail.com>
Date: Mon, 21 Jul 2008 21:32:52 -0700 (PDT)
Local: Tues, Jul 22 2008 12:32 am
Subject: example of a logic bug using pseudocode
Gentleman,

I have the following question:

9. Present an example of a logic bug using pseudocode and explain your
answer. (10 points) I just want the group to verify if my answer is
correct.
Here is my answer:

Temperature = 70
 if (Temperature >69) and (Temperature < 100 )
        THEN
    openWindows;
Will work because if temperature is higher than 69 degrees and
temperature is lower than 100 degrees windows will open.

The code generated: A numbered list from 70 - 99
--------------------------------------------------------------------------- --------------------------------------------------------------------------- -----------------------

I then ran erroneous code below changing the "and" operator to "or"
which is an infinite loop.

Temperature = 70
 if (Temperature >69) or (Temperature < 100 )
        THEN
   openWindows;

Won't work because windows will stay closed due to temperature will
always be under 100 degrees the fault lies with the "or" "||" operator
which was used instead of the "and" (&&) operator.
The code generated:  an infinite loop.

Thank You,

Ray


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Geoffrey Summerhayes  
View profile
 More options Jul 22, 1:44 pm
From: Geoffrey Summerhayes <sumr...@gmail.com>
Date: Tue, 22 Jul 2008 10:44:19 -0700 (PDT)
Local: Tues, Jul 22 2008 1:44 pm
Subject: Re: example of a logic bug using pseudocode
On Jul 22, 12:32 am, popeyerayaz <popeyera...@gmail.com> wrote:

Two things: First, you obviously haven't tested this with actual code,
otherwise you would have noticed something. Secondly, you can't get an
infinite loop without actually having a loop there. You have an
assignment
followed by a forward branching if, no loop.

----
Geoff


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ashesh  
View profile
 More options Jul 23, 3:30 am
From: Ashesh <ashesh.amba...@gmail.com>
Date: Wed, 23 Jul 2008 00:30:38 -0700 (PDT)
Local: Wed, Jul 23 2008 3:30 am
Subject: Re: example of a logic bug using pseudocode

> Temperature = 70
>  if (Temperature >69) or (Temperature < 100 )
>         THEN
>    openWindows;

Isn't temperature always < 100 or > 69? Where is the loop you're
talking about? What do you mean by 'won't work' ? This piece of code
will always work because the if conditions will hold for all real
values, i.e. it'll always be true.

Moreover, I don't get it - you're first introducing a bug yourself,
and then making statements about bugs in pseudocode? What exactly is
the point here?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google