Skip to content

Instantly share code, notes, and snippets.

@nelson6e65
Created May 11, 2015 17:50
Show Gist options
  • Save nelson6e65/e37f6bc5eb3424e49cf2 to your computer and use it in GitHub Desktop.
Save nelson6e65/e37f6bc5eb3424e49cf2 to your computer and use it in GitHub Desktop.
//No conozco mucho de C, pero más o menos así iría el ciclo do:
char l;
bool valida; //Definimos un variable para almacenar si la letra es válida o no (flag)
do {
printf("\nIngrese una letra: ");
scanf("%c", &l);
if (l == 's' || l == 'S' || l == 'n' || l == 'N') {
valida = true;
printf("\nLetra válida."); // Podría incluirse mejor al final del procedimiento (fuera del while), ya que no se volverá a entrar al ciclo 'do' si es válida
} else {
valida = false;
printf("\nLetra inválida; vuelva a intentar.");
}
} while (valida == false); //O también while(!valid); -> Sólo se repite cuando no es válida.
//el resto del procedimiento...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment