A loop executing 15 times is indeed a heavy loop needing optimisation.
But assuming optimisaton for size, what about removing this loop entirely? You would save up to several hundred bytes in the code section.

A loop executing 15 times is indeed a heavy loop needing optimisation.
But assuming optimisaton for size, what about removing this loop entirely? You would save up to several hundred bytes in the code section.

Sorry, in my first post is rong code:

#define NUM_STATIONS 15
must be

#define MENU_SIZE 15

the loop must run for all number of stations from database: num_stations = stations in data base, menu_size = scrooling menu with max 15 line

1 If cursor in in first line of MENU and I wont to move up, rather than jumping to line 75, cursor jump to line 61. ( max stations - 15)
2. If I scroll down all is fine: when cursor get line 75 and move down one line, jump to line 1 in MENU what is right.

By saying "optimise" you make other think about code optimisation (e.g., for speed), which is something completely different.
It is impossible to guess what you want to do by looking at a piece of broken and incomplete code. You might want to use an array to store some information, and instead of if-else statements, access that array at a specified index (index = cmd->curmenupos).

Obvious (to me at least) question is the value of "cmd->curmenupos" changing inside the loop?

If not changing, I see no need for the "else if" statements being used. My hint only applies if value is not changing inside loop.

Note: I am guessing this is a homework assignment; therefore I am not giving you anymore help on it.

Hint: The answer is more a math answer than a programming logic answer.

Tim S.

Last edited by stahta01; 01-02-2013 at 09:58 PM.

"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

If you want help with optimising a loop, it would be helpful if you provide all information relevant to optimising that loop.

On a visual examination of your code, it appeared that cmd->curmenupos does not change, hence stahta01's suggestion. You have now revealed that it does change.

As such, you are wasting people's time. I suspect deliberately.

Right 98% of the time, and don't care about the other 3%.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.