Felix Zhang (TA, he/him) 👋 [email protected]

Disha Sikaria (LA, she/her) 👋 [email protected]

Please email us (cc both of us) if you have ANY questions!! 🤗

slides link: bit.ly/cs31w22_week3

credit: nikki woo+zhehui for examples

Announcements

Project 2 due 9PM Sunday, Jan 23

List of test cases to check for:

2 files to turn in: payment.cpp and report.docx/doc/txt

<aside> ❗ Please do NOT share your code/work with your classmates by posting on Piazza, sending via email or just letting them read it in general!

</aside>

<aside> 👩🏻‍💻 In-person week 5 thoughts?

</aside>

[Review] For Loops

For loops are used for repetition.

for (*initialization; stay-in-loop-condition; prepare-for-next-iteration*) {
	*statement/s-to-execute;*
}

for (**int i = 1**; i < 5; i += 1) { //you can define int i only to exist during loop.
	cout << "hi";
}

1 < 5
2 < 5
3 < 5
4 < 5 (4 times)
5 < 5 Fails

1. int i = 1
2. i < 5
3. outputs "hi"
4. i = i + 1  (i += 1)
5. i < 5
  1. *initialization (*Statement 1) is executed (one time) ☝️

    before the execution of the code block.

  2. *stay-in-loop-condition (*Statement 2) defines the condition ♻️

    for executing the code block.