Baixe o app para aproveitar ainda mais
Prévia do material em texto
Estrutura de Repetição Repetição For Program TesteFor; Var i: integer; Begin For i:=0 to 10 do // (para ir de X até y faca)) Writeln (i); End. Características: Quando se pode definir Inicio e Fim! Repetição While (Uaio) Program TesteWhile; Var Num: integer; // Características do While: Vai executar enquanto a sentença for V. Begin // Não é necessário definir inicio e nem fim! Num:= 1 While (Num > 0) do Begin Writeln (' Insira um número: '); Read (Num); End; End. Repetição While Contador Características: Defini um inicio e fim! Program Testewhilecontador; var Cont: integer; Begin Cont:=0; While (Cont<=10) do Begin Writeln (Cont); Cont:= cont + 1; // (Não deixa o programa em Looping Infinito) End; End. Repetição REPEAT CARACTERÍSTICAS: EXECUTA A CONDIÇÃO AO FINAL E A TESTA; PROGRAM TESTEREPEAT; VAR NUM, CONT: INTEGER; BEGIN CONT:=0 REPEAT CONT:= CONT+1 WRITELN (' INSIRA UM NÚMERO'); READ(NUM) WRITELN (' QUADRADO: ', NUM*NUM); UNTIL (CONT>=3); END. INTERROMPER LAÇO DE REPETIÇÃO PROGRAM TESTE_INTERROMPER; VAR i:integer; begin i:=0; repeat i:= i + 1; if (i=5) then break; writeln (i); until (i=10); end.
Compartilhar