ALGORITHM AND PROGRAMMING
Program
Control: Repetition
1. For :
(exp1;exp2;exp3) statement;
For
or loop is used when, we want to do the same command input as before for a
certain number of times.
there are two types of loop:
-
infinite loop : usually appear when there are errors in the coding
-
nested loop : its a loop in a loop, the repetition will start from the inside.
2. While :
while (exp) statements;
For
While, it is actually a condition where it checks the command input above it
whether its true or false. it checks the condition before the program below it
is executed.
it will execute the command input
until the condition is false.
3. Do-While
do{statements};} while
In
this case, do while is kinda the combination of the for and the do. But, the
difference is in this case, it will execute the program first and then after
that, it checks the validation of the statements, and it will continue running
until the condition is false.
4. Break
break;
break
is used when we want the loop to end.
5. Continue
continue
is used when a certain condition is set, and then if it matches the condition
it will skip the statements below it until it reaches the of the loop, and then
it continues the lopp again.
I would like to post this in english, so that everyone can read it internationally, hope you enjoy it..
2201741933
Raditya Saskara
binus.ac.id
skyconectiva.com
-trust me, its not easy.
Paul Deitel & Harvey Deitel. (2016). C how to program : with an introduction to C++. 08. Pearson Education. Hoboken. ISBN: 9780133976892. Chapter 3 & 4
Komentar
Posting Komentar