Lecture 7
Lecture 7
Puru
with
CS101 TAs and CSE Staff
Lecture 7:
•
–
•
–
while
repeat
while
repeat
int n;
cin >> n;
while(n>=0) {
cout << n; // print
cin >> n; // next number
}
•
•
•
•
while (true){
cin >> nextmark;
if(nextmark > 100)
continue;
if(nextmark < 0)
break;
sum = sum + nextmark;
}
cout << sum << endl;
02/08/19 Autumn 2019 CS101@CSE IIT Bombay 12
02/08/19 Autumn 2019 CS101@CSE IIT Bombay 13
•
–
– …
–
–
–
•
•
–
–
–
cin >> n;
while (n<=0) // get valid input
cin >> n;
repeat (n-2) {
num = first + second; // state update
first = second; // state update
second = num; // state update
cout << “ “ << num;
}
}
–
–
–
–
•
•
cin >> n;
while (n<=0) // get valid input
cin >> n;
•
–
–
–
–
•
•
•
•
Initialization
Condition False
True
Body
Update