Langsung ke konten utama

Program Control: Repetition

Program Control: Repetition

Sub Topics :

Program Control - Repetition:
Repetition Definition
For
While
Do-While
Repetition Operation
Break vs Continue

Repetition Definition
One or more instruction repeated for certain amount of time. Number of repetition can be predefined (hard
-coded in program) or defined later at run time
Repetition/looping operation:
for
while
do-while


For

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


While
Syntax :
while (exp) statements;
or:
while(exp){
statement1;
statement2;
…..
}


Do-While
Syntax :
do{
< statements >;
} while(exp);

Keep executing while exp is true
exp evaluation done after executing the statement(s)


Repetition Operation
In while operation, statement block of statements may never be executed at all if exp value is false
In do-while on the other hand statement block of statements will be executed min once
To end the repetition, can be done through several ways:
-Sentinel
-Question, should the repetition continue?


Break vs Continue
break:
ending loop (for, while and do-while)
end the switch operation
continue:
skip all the rest of statements (subsequent to the skip statement) inside a repetition, and continue normally to the next loop


Summary
Repetition is a condition which is one or more instruction repeated for certain amount of time
3 types of repetition/looping in C:

-for

-do while

-while

2201760945
Skyconnectiva
Kevin Orlando Sutanto

Komentar

Postingan populer dari blog ini

Sorting & Searching

Sorting & Searching SUB TOPICS : Bubble Sort Selection Sort Insertion Sort Quick Sort Merge Sort Linear Search Binary Search Interpolation Search Sorting •        Sorting needs to speed up searching operation in a list. •        Sorting type: –       Ascending –       Descending Sorting algorithm: 1. Internal sorting     All data to be sorted are loaded to RAM 2. External sorting     Sorting process using secondary storage •        Simple: –                       Bubble sort –                       Selection sort –          ...

Cloud Computing Services

Cloud Computing Services What is Cloud? Cloud refers to a network or internet, which is present at certain place which is accessible from any location over public network or private network Cloud Computing refers to manage, configuring, and accessing the applications online. It offer online data storage, compute, network infrastructure and application which delivered as a network services. Cloud computing tends to separate infrastructure with business, whereas terms "infrastructure" refer to hardware, networking, and software which managed as one entity. And terms "Business" refers to procedural workflow, strategic enforcement, etc Deployment Examples Social networking : Facebook, Instagram, LinkedIn, etc. Data sharing / collaboration : Email, Dropbox, etc. Education : Quipper, Smart Campus, E-Learning, E-Library, etc. Business : Office application : Online shop portal, Google doc, Personal / Corporate                  ...

File Processing

FILE PROCESSING SUB TOPICS : Files and Streams File Definition Open File Close File Input File Output File Files and Streams Streams Definition •       To keep key in data from keyboard need to be saved at secondary storage device as a data file. •       Stream is a sequence of character. All input and output data is a stream. C sees file as a stream. •        When a C program run, there are three (3) standard streams activated: 1. Standard Input Stream     Controlling input stream from keyboard 2. Standard Output Stream     Controlling output stream to the monitor 3. Standard Error Stream     Controlling the error messaging •        Each stream associated with a file. File Definition •        File is a collection of record •    ...