skip to main |
skip to sidebar
Repetition
Three (3) main things in repetition process are :
- Initialization
- Evaluation / checking
- updating - increment & decrement process
- before start write a C++ program, we need to identify LCV (Loop Counter Variable).
- step 2 , identify or determine the operation.
- how many it will loop / repeat
- what is the initial value, e.g counter = 1, cin>>mark;
- checking or evaluate , e.g counter <10
- update . e,g counter = counter + 1, cin >>mark
how to form a condition.
- e.g while (variable < = condition)
- your condition must generate an answer either "TRUE" or "FALSE"
- using an operator :
- relational - >, < , >= , <=, == , !=
- logical - &&, || , !
LCV - Loop Counter Variable
- to determine a LCV, we need to understand the problem either we know the counter controlled or we don't know how many times the process will loop (sentinel controlled).
- counter controlled - counter < 10, bil < 9 etc.
- sentinel controlled - choice != 'y' , mark <0. etc
No comments:
Post a Comment