On Jul 22, 12:32 am, popeyerayaz <[EMAIL PROTECTED]> wrote:
> 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.

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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to