Linguagem C Estruturas de Controle Repetição Regis Pires Magalhães [email_address]
Laços condicionais while  (expressão) { comandos; } do  { comandos; }  while  (expressão); Laço condicional com teste no início Laço condicional com teste no final
Laço condicional ... int   i   =   0 ; while   ( i   <   10 )   { printf ( &quot; olá !&quot; ); i   =   i   +   1 ; } ...
Laços usando  for for   ( inicializacao ;   condicao ;   incremento )   { codigo ; } int   i;   for   ( i   =   0 ;   i   <   10 ;   i++ )   { printf ( &quot; olá !&quot; ); } Em C, a declaração da variável deve ser realizada antes do  for .
I’ll not throw paper airplanes in class
Exemplo – Linha de * #include   <stdio.h> int  main() { int  i, n; printf ( &quot;Digite um numero: &quot; ); scanf ( &quot;%d&quot; , &n); for  (i=0; i < n; i++) { printf ( &quot;*&quot; ); } printf ( &quot;\n&quot; ); return (0); }
Exemplo – Quadrado de * #include   <stdio.h> int  main() { int  coluna, linha, n; printf ( &quot;Digite um numero: &quot; ); scanf ( &quot;%d&quot; , &n); for  (linha=1; linha <= n; linha++) { for  (coluna=1; coluna <= n; coluna++) { printf ( &quot;* &quot; ); } printf ( &quot;\n&quot; ); } return (0); }
Exemplo #include   <stdio.h> int  main() { int  i, j; for  (i = 0, j = 100; i < 10 && j > 50; i++, j = j - 10) { printf ( &quot;i: %d\n&quot; , i); printf ( &quot;j: %d\n&quot; , j); } }
Controlando loops int   i; for   ( i   =   x ;   i   <   y ;   i ++)   { if   ( i   %   19   ==   0 )   { printf ( &quot;%d&quot; ,  i ); break ; } } int   i; for   ( i   =   0 ;   i   <   100 ;   i ++)   { if ( i   >   50   &&   i   <   60 )   { continue ; } printf ( &quot;%d&quot; ,  i ); } break e continue

Linguagem C 04 Estruturas De Repeticao

  • 1.
    Linguagem C Estruturasde Controle Repetição Regis Pires Magalhães [email_address]
  • 2.
    Laços condicionais while (expressão) { comandos; } do { comandos; } while (expressão); Laço condicional com teste no início Laço condicional com teste no final
  • 3.
    Laço condicional ...int i = 0 ; while ( i < 10 ) { printf ( &quot; olá !&quot; ); i = i + 1 ; } ...
  • 4.
    Laços usando for for ( inicializacao ; condicao ; incremento ) { codigo ; } int i; for ( i = 0 ; i < 10 ; i++ ) { printf ( &quot; olá !&quot; ); } Em C, a declaração da variável deve ser realizada antes do for .
  • 5.
    I’ll not throwpaper airplanes in class
  • 6.
    Exemplo – Linhade * #include <stdio.h> int main() { int i, n; printf ( &quot;Digite um numero: &quot; ); scanf ( &quot;%d&quot; , &n); for (i=0; i < n; i++) { printf ( &quot;*&quot; ); } printf ( &quot;\n&quot; ); return (0); }
  • 7.
    Exemplo – Quadradode * #include <stdio.h> int main() { int coluna, linha, n; printf ( &quot;Digite um numero: &quot; ); scanf ( &quot;%d&quot; , &n); for (linha=1; linha <= n; linha++) { for (coluna=1; coluna <= n; coluna++) { printf ( &quot;* &quot; ); } printf ( &quot;\n&quot; ); } return (0); }
  • 8.
    Exemplo #include <stdio.h> int main() { int i, j; for (i = 0, j = 100; i < 10 && j > 50; i++, j = j - 10) { printf ( &quot;i: %d\n&quot; , i); printf ( &quot;j: %d\n&quot; , j); } }
  • 9.
    Controlando loops int i; for ( i = x ; i < y ; i ++) { if ( i % 19 == 0 ) { printf ( &quot;%d&quot; , i ); break ; } } int i; for ( i = 0 ; i < 100 ; i ++) { if ( i > 50 && i < 60 ) { continue ; } printf ( &quot;%d&quot; , i ); } break e continue