Você está na página 1de 5

Estruturas de repetição

1) While

 Visualg

Enquanto teste faca


-
-
-
Fimenquanto

 C

While (teste)
{
-
-
-
}

Ex: #include <iostream>

Using namespace std;

main() {

while (i<= 1000)

Cout<<i;

i=i+1

Em C, operações de incremento/decremento de variáveis podem ser escritas de diferentes


formas

x=x+1  x++ ou ++x

x+x-1  x-- ou --x


Refazendo o ultimo exemplo:

#include<iostream>

Using namespace srd;

main(){

int i=1;

while(i<=1000){

cout<<i;

i++

2) Do...while

VISUALG

Repita
-
-
-
Ate teste

do{
-
-
-

}while(teste);

Ex:
#include<iostream>
using namespace std;
main(){
int i=1;
do{
cout<<i;
++i;

}while(i<=1000

3) FOR

VISUALG

Para VC <- VI ate VF Faca

fimpara

For(area1;área_teste;rea3)

Ex1:

#include<iostream>

using namespace std;

main(){

int i;

for(i=1; i<=1000;i++){

cout<<i;

}
Ex2:

#include<iostream>

using namespace std;

main(){

int i;

for(;i<=100;){

cout<<1;

i++;

Ex3:

#include<iostream>

using namesapace std;

main(){

int a,b;

for(a=1,b=1;a+b<=100;a++,b++)

Cout<<a+b;

Ex4:

#include<iostream>

using namespace std;

main(){

for(; ;){

cout<<”loop infinito;”;

}
Ex5:

Main(){

For(; ;);

Você também pode gostar