Program Control : Repetition
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
Repetition : FOR
Syntax :
for(exp1;exp2;exp3){ exp1 is initialization
statement1; exp2 is condition
statement2; exp3 is increment or decrement
………
}
Example :
for(int i =0;i<number;i++){
number1 = number1 + 2;
number2 = number2 / 2;
}
- Infinite Loop
- Nested Loop
Repetition : WHILE
- While check first then do the statement
Repetition : DO WHILE
- Do the statement once then check the condition
NIM : 2201755781
Binus.ac.id
Skyconnectiva.com
Nama : Virnando Tan Wijaya
Binus.ac.id
Skyconnectiva.com
Nama : Virnando Tan Wijaya
Reference
https://binus.ac.id/
Comments
Post a Comment