how to optimize "for" statement

This is a discussion on how to optimize "for" statement within the C Programming forums, part of the General Programming Boards category; I have this code and I wont to optimize them:
here is a scrolling menu with max 15 line and ...

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).

"...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 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.