LOOPING
 
Looping is an action to do similar things many times, for example showing the words "electrical engineering UAD" a hundred times.
Conditional looping "check-run": WHILE
The structure of looping while has the following form:


While (kondisi)
{
     Pernyataan
}
 
 



In this case the statement will run continuously for the condition true. If the initial state value condition then statement will not be executed at all.

Conditional looping “periksa-jalankan”: DO-WHILE
Do
{
     Pernyataan
}
While (kondisi);
 
 Conditional looping do-while has the following form;



This form of the command above to read:
Kerjakan pernyataan selama kondisi bernilai true.
In this structure the statement at least will be done one time. The statement must have been carried out, as a first step the looping structures do-while working on the statement, then followed the testing against the condition. This structure is particularly suitable for programs that don't need testing first before working on the statement.
Looping with FOR
For (Inisialisasi; kondisi; perubahan)
{
     Pernyataan;
}
 
The structure of looping for has the following form:


Structure for used for looping with number of repetitions have been ascertained.
Details:
Initialization: Give the initial value on a variable control
Conditions: to control the looping, continued/end
Change: State of change control values, i.e. addition or subtraction.

III. DISCUSSION OF THE EXPERIMENT AND STEP
Conditional looping “periksa-jalankan”: WHILE
Program VI-1


#include <iostream.h>                                (1)
#include <conio.h>                                   (2)
main ()                                              (3)
{    char nama [80];                                 (4)
     int tombol ;                                    (5)
     tombol='Y' ;                                    (6)
     while ((tombol == 'Y') || (tombol =='y'))       (7)
           {
           cout << "Masukkan nama anda = ";                (8)
           cin >> nama;                               (9)
           cout << "Halo " << nama << endl << endl;   (10)
           cout << "Apakah mau mengulangi (Y/T)? ";   (11)
           tombol = getch ();                         (12)
cout << endl << endl;                      (13)
           }
     cout << "Selesai";                              (14)
     }
 
 










Results running program




Baris
Keterangan
1.
Is a program to call the header files in the form of library operations stream.
2.
Is a program to call the header files in the form of library operations console (monitor & keyboard)
3.
The main functions of the program in C++
4.
Limit characters in the "name" is 80 characters.
5.
The Program outputs in the form of an integer or integer value.
6.
Is variable. When the remove then would instantly "done"
7.
Stated condition Y/y
8.
Is a great Program and display the output statement
9.
Is a great program and the input statement
10.
The statement display output on the "name"
11.
Is a great Program and display the output statement
12.
Is a program specialized for character input and repeat instruction
13.
To provide a range or enter on view
14.
Is a great Program and display the output.

Conditional looping  “jalankan-periksa”:DO-WHILE
#include <iostream.h>                                          (1)
main ()                                                        (2)
{     int cacah = 0;                                           (3)
      float nilai, jumlah = 0, rerata;                         (4)
      cout << "MENGHITUNG RERATA NILAI\n";                     (5)
      cout << "Masukkan nilai"                                
      << "(masukkan bilangan negatif untuk mengakhiri) \n\n";  (6)
      do { cacah++;                                            (7)
            cout << "Data ke-" << cacah << " = ";              (8)
            cin >> nilai;                                      (9)
            jumlah = jumlah+nilai; }                           (10)
      while (nilai >= 0);                                      (11)
      rerata = jumlah/cacah;                                   (12)
      cout << "\nBanyaknya data = " << cacah;                  (13)
      cout << "\nJumlah = " << jumlah ;                        (14)
      cout << "\nRerata = " << rerata ;                        (15)
}
 
Progarm VI-2










Results running program
Counting cacah ++ is to count up/down a numeric value with a certain multiples..
Baris
Keterangan
1
Is a program to call the header files in the form of library operations stream.
2
The main functions of the program in C++ is a function of the main
3
Indicates that the integer-shaped counter and start from 0
4
Input Program to calculate the number and average value of the numbers which we input after the program is run.
5
The Program output statement
6
The Program output statement
7
To count up a numeric value in this memcacah rising by increments of 1
8
The Program output statements and counter input
9
Input Program statements
10
Summation functions
11
The value in the do is greater than or equal to 0
12
Average function
13
The Program output statement
14
The Program output statement
15
The Program output statement





Break iteration: BREAK & CONTINUE
Program VI-3


#include <iostream.h>                           (1)
main ()                                        
{    int i=0 ;                                  (2)

     cout << i;                                 (3)
     do {                                                  i++;                                 (4)
           cout << " - ";                       (5)
     //         if (i == 4)                     (6)
     //              break;                     (7)
           cout << i;                           (8)
     } while (i < 10);                        (9)
     cout << "\nSelesai\n";                   (10)
}
 
 








Display the results of the execution of the program
So the function Syimbol//is to translate all the characters after//as a comment or did not enter the executable compiler.After removing the two syimbol//Produces the following display
So the function keyboard break is issued a compiler execution of program structure after a certain condition is met. Replace the keyboard functionality break with continue, resulting in a display as follows
So keyboard functionality continue is to direct execution to a round, the next iteration in the loop statement or resume execution compilers from the structure of the program after a certain condition is met.
Baris
Keterangan
1.
Is a program to call the header files in the form of library operations stream
2.
as a counter variable to indicate the amount of writing C++ already displayed, initially filled with 0
3.
Program the output statement
4.
to count up a numeric value in this memcacah rising by increments of 1
5.
Program the output statement
6.
translate all characters after//as a comment or did not enter the executable compiler
7.
removing the eksekussi compiler from the structure of the program after a certain condition is met.
8.
output Program statement
9.
conditions of less than 10
10.
Program the output statement

FOR looping
Program VI-4


#include <iostream.h>
main ()
{
      int i;
      for (i=1; i<=20; i++) {
            cout << "kalang ke-" << i << endl;
            }
}
 
 





Display the results of the execution of the program

for (i=1; i<=20; i++) { 
 
Change instruction                                                           
(a)for (i=10; i<=20; i++) {
(b)for (i=1; i<=20; i++) {
(c)for (i=1; i<=20; i=i+2) {

Display the results of the execution of the program

a.       the influence that occurred    for (i=10; i<=20; i++) {
b.      the influence that occurred for (i=1; i<=20; i++) {
c.  the influence that occurred for (i=1; i<=20; i=i+2) {
The influence that occurred for the third such change is
a. the influence going to for (i = 10; i < = 20; i ++) {
For a numeric value equal to 10, then to a value less than or equal to 20 to 10 using scintillation multiples 1 (order)
b. influences that occur to for (i = 1; i < = 20; i ++) {
For a numeric value equal to 1, then to a value less than or equal to 10 to 1 using scintillation multiples 1 (order)
c. the influence going to for (i = 1; i < = 20; i = i + 1) {
For a numeric value equal to 1, then to a value less than or equal to 20 to 1 using scintillation multiples of 2

looping FOR: Tabel Perkalian
Program VI-5


#include <iostream.h>
#include <iomanip.h>
main ()
{
     for (int i=1; i<=10; i++) {
           for (int j=1; j<=20; j++) {
                cout << setw (5) << i*j;
           }
           cout << endl;
           }
      }


 
 






Display the results of the execution of the program
The replacement of the number 5 in parentheses on function setw () into 3 and 8 are as follows.
Display the results of the execution of the program after a change in the number 3.
Display the results of the execution of the program after a change in the number 8.
So the function setw () is to set the width of a data display and Function make the look in right align with the width determined by the existing values in parentheses.


       I.            Task
1.      Flowchart To calculate the number and average
a.      Use looping structures WHILE
 





















b.      Use looping structures DO-WHILE














Ya
 


Tidak
 
 














1.      Compute the number and average
a.      Use looping structures WHILE
Text Box: #include <iostream.h>
#include <conio.h>
main ()
{
	clrscr();
	int cacah=1;
	float N, nilai, jumlah = 0, rerata;
	cout << "Banyaknya nilai = ";
	cin >> N;
	while (cacah <= N) {
		cout << "Data ke-" << cacah << " = ";
		cin >> nilai;
		jumlah=jumlah+nilai;
		cacah++;
	}
	rerata = jumlah/N;
	cout << "\nJumlah = " << jumlah;
	cout << "\nRerata = " << rerata;
}

 










Display the results of the execution of the program using a looping structure WHILE

b.      Use looping structures DO-WHILEText Box: #include <iostream.h>
#include <conio.h>
main ()
{
	clrscr();
	int cacah=0;
	float N, nilai, jumlah = 0, rerata;
	cout << "Banyaknya nilai = ";
	cin >> N;
	do {
		cacah++;
		cout << "Data ke-" << cacah << " = ";
		cin >> nilai;
		jumlah=jumlah+nilai;
	} while (cacah < N);
	rerata = jumlah/N;
	cout << "\nJumlah = " << jumlah;
	cout << "\nRerata = " << rerata;
}




Display the results of the execution of the program using a looping structure DO-WHILE



2.      temperature conversion Table
The use of looping Structures DO-WHILE for creation of temperature conversion table from Celsius to Farenheit, Reamur, and Kelvin temperature, ranging from 0 ºc to 100 ºc by 5ºc.



Text Box: #include <stdio.h>
#include <math.h>
main ()
{  int C = 0;
	float F, R, K;

	puts("TABEL KONVERSI SUHU\n------------------");
	puts("	C	F	R	K");
	do {
		F = 9.0/5.0*C + 32;
		R = 4.0/5.0*C;
		K = C + 273.25;
		printf("%8.1d %8.1f %8.1f %8.1f\n",C,F,R,K);
		C += 5;
	} 	while (C <= 100);
}
 












Display the results of the execution of the program using a looping structure DO-WHILE
Conclude
1. the structure of looping while, do ... while, for and a description of the syntactic structure while, do ... while, for
a. while looping Structures, the statement will run continuously for the condition nernilai true. If the initial state value condition then statement will not be executed at all.
b. structure of looping the do ... while, working on the statement as long as the condition is true. working on the statement, then followed the testing against the condition.
c. structure of looping Structures for, for used for looping with number of repetitions have been ascertained.
2. Flowchart is a sequence of processes in the system by showing media tool input, output and the type of storage medium in the process of data processing. Flowchart is also a sequence of instructions that is described with a specific symbol to solve problems in a program.

    II.            REFERENSI
Ø  Modul Praktikum Dasar Pemrograman Kartika Firdausy, S.T.,M.T