Jump to content

Simplificar código


JoaoNascimento
 Share

Recommended Posts

Existe alguma maneira facil de simplificar este código??

LAB::ColocarCursorNaPosicao(14,10);
	LAB::ColocarCursorNaPosicao(39,10);
	LAB::ColocarCursorNaPosicao(14,12);
	LAB::ColocarCursorNaPosicao(38,12);
	LAB::ColocarCursorNaPosicao(14,14);
	LAB::ColocarCursorNaPosicao(38,14);
	LAB::ColocarCursorNaPosicao(14,16);
	LAB::ColocarCursorNaPosicao(38,16);
	LAB::ColocarCursorNaPosicao(14,18);
	LAB::ColocarCursorNaPosicao(38,18);
	LAB::ColocarCursorNaPosicao(14,20);
	LAB::ColocarCursorNaPosicao(39,20);
	LAB::ColocarCursorNaPosicao(14,22);
	LAB::ColocarCursorNaPosicao(38,22);
	LAB::ColocarCursorNaPosicao(14,24);
	LAB::ColocarCursorNaPosicao(38,24);
	LAB::ColocarCursorNaPosicao(14,26);
	LAB::ColocarCursorNaPosicao(38,26);
	LAB::ColocarCursorNaPosicao(14,28);
	LAB::ColocarCursorNaPosicao(38,28);
Link to comment
Share on other sites

Podes usar dois loops for.

Neste código, estou a assumir que o 39 (em oposição ao 38) na segunda linha era um erro, e se não for, podes colocar antes do for:

int rep = 10;
int i,j;
int pos[2] = {14, 38};
int y = 10;
for(i = 0; i < rep; ++i) {
  for(j = 0; j < 2; ++j) {
    LAB::ColocarCursorNaPosicao(pos[j], y);
  }
  y += 2;
}

Outra forma, caso apenas tenhas dois valores no primeiro parâmetro:

int rep = 10;
int i,j;
int pos[2] = {14, 38};
int y = 10;
for(i = 0; i < rep; ++i) {
  LAB::ColocarCursorNaPosicao(pos[0], y);
  LAB::ColocarCursorNaPosicao(pos[1], y);
  y += 2;
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.