Skip to main content

Algorithm and Programming : Repetition

Repetition

Program Control : Repetition

Meaning of Repetition

Instruksi yang digunakan berulang selama waktu tertentu ( memiliki batas tertentu ). Batas dari pengulangan bisa ditentukan.

Kind of Repetition :

Repetition : For

   Syntax 
for(exp1; exp2; exp3)
{
  statement1;...
 }
exp1 :  initialization
exp2 :  conditional
exp3 :  increment or decrement
exp1, exp2 and exp3 are optional

Infinite Loop

Loop yang tidak memiliki kondisi untuk berhenti. 

Untuk membuat loop berhenti adalah dengan menggunakan BREAK;

Nested Loop

Memiliki Loop didalam Loop. Dan loop yang dimulai adalah Loop yang didalam.

Repetition : While

Statement akan dilakukan setelah kondisi yang ditetapkan sudah benar.

   Syntax 

while(exp){
   statement1;

           exp :  conditional

Repetition : Do - While

Statement dilakukan terlebih dulu satu kali, kemudian diperiksa apakah sesuai dengan kondisi atau tidak.

   Syntax 

do{
    < statements >;
} while(exp);

           exp :  conditional

Break and Continue

Break berfungsi untuk mengakhiri Loop ( for, while, do-while).
Continue berfungsi untuk melewati sebuah perintah, dan dilanjutkan ke pengulangan berikutnya.











Comments

Popular posts from this blog

Cloud Storage

Cloud Computing atau nama lainnya adalah Komputasi Awan adalah teknologi yang menjadikan internet sebagai tempat penyimpanan database, aplikasi dan masih banyak lagi. Layanan Cloud Computing 1. Software as a Service (SaaS) Layanan pemakaian teknologi mengenai pemakaian software yang telah disediakan contohnya : gmail, outlook mail 2. Platform as a Service (PaaS) Cloud Computing dapat menyewakan sistem operasi, database engine, framework aplikasi untuk menjalankan aplikasi yang kita buat. Contohnya : windows azure  3. Infrastructure as a Service (IaaS) Cloud Service dapat memberikan layanan infrastruktur IT. Contohnya CPU, penyimpanan data, memory dan lainnya dapat disewa.  Cloud Deployment Model Deployment model define the type of access to the cloud. Type of access : 1. Private cloud       - Single organization only       - Managed by the org or a 3rd party       - On ...

Summary Semester 1

Assignment #1  1. Compound Word Jojo has just learned about compound words, which occurs when two or more words are joined to make one longer word. For example the English word footpath, composed of two words "foot" and "path". She wants you to make one such word, given two words that make up the compound word. 2. Birthday Cinema * Jojo, Lili, and Bibi wants to treat their N friends. They want to treat their N friends to watch a movie. Each movie ticket cost 1 point. Luckily there is a promo, if you buy 2 tickets you get 1 for free. How many points do they need to spend to buy tickets for all of them. 3. Counting Number Lili has just learned how to count from 1 to n, while Jojo just recently learned how to use a calculator. When Lili counts from 1 to n, Jojo always adds the numbers that Lili mentions. Jojo asked for your help to check if he used the calculator correctly, he needs you to calculate the number he is supposed to get. 4. Boom...

Sorting And Searching

Sorting Sorting is needed to speed up the process of searching a data. There are two kinds of sorting :  ascending from the lowest to the highest. And descending from the highest to the lowest. Type of sorting : 1. Bubble sort, compares the value of the current data with the immediate next data and swap the according to the requirement and goes till the last element. 2. Selection sort , a selection of an element position from the start with the other rest of the element. Element are compared and exchanged depending on the condition and then selection position is shifted to the next position till it reaches to the end 3. Insertion Sort, one element from the top is selected and is compares to the other rest of the elements down the line and inserted to another position and rest of the elements are shifted accordingly. 4. Quick shot, it picks an element as pivot and partitions the given array around the picked pivot. 5.  Merge shot,  This t...