Re: Nested If Statements


[Prev][Next][Index][Thread]

Re: Nested If Statements



At 10:01 AM 6/23/97 -0400, you wrote:
>I'm working on a program on a TI-82 and it must contain multiple nestings of
>If-Then-Else statements.  My manual for the calc mentions that nesting single
>If statements is OK, but no mention is made for nesting If-Then or
>If-Then-Else.  Is there a limit to the number of levels I may nest to?
Looking
>at the program as it is formatted in the machine is confusing, too, since
it's
>hard to tell which End corresponds to which Then or Else.  I'm a C++
>programmer, so I'd really like to use indentation and brackets, but
obviously I
>can't.  I think my calc is getting confused about which End goes with which
>Then or Else.
>
>Has anyone out there had similar problems or have any hints or suggestions?
> BTW, I'd like to avoid using Lbl and Goto - many years of programming
classes
>have drilled into my head that that is "bad style", but I guess if that's my
>only option, I'll have to use it.

If I ever have the need to nest multiple If-Then-Else statements, I usually
write my code first, then I go back through and count the nests like this:

(Normally I use one continuous line for nested code but this is only an
example)

  CODE                    NEST COUNT (at the end of each line)
-------------------------------------------------------------
:If A=0:Then              1
:1->B:If B=1:Then         2
:If [A](1,1):1->C         2
:End                      1
:Else                     1
:If B=0:Then              2
:1->B:Else                2
:0->B:End                 1
:End                      0

I hope this helps out.  One thing you should know is that if you don't get
back to zero in your nesting you will notice a decrease in the speed of
your program and there is the chance that it could crash with an "out of
memory" error.  I hope I could be of help.

Signed,
Thomas J. Hruska

|----------------------------------------------------|
|             Shining Light Productions              |
|      "Meeting the needs of fellow programmers"     |
|                                                    |
|   C/C++ programs                                   |
|   QBasic programs                                  |
|   JavaScript                                       |
|   TI-Basic                                         |
|   HTML                                             |
|                                                    |
| Search for our web site at                         |
| www.geocities.com/SiliconValley/Heights/8504/      |
|                                                    |
| We use a dynamic web server for most of our        |
| documents!!!                                       |
| Soon to go to a full JavaScript 1.1 web site!      |
|----------------------------------------------------|


References: