class: title # Loops and Conditionals ## CSC 161 – January 27, 2026 --- # Agenda for Today 1. Token Events 2. Upcoming Work 3. Discussion 4. Code Style 5. Lab 6. Wrap Up --- # Token Events ## CS Extra: Major Declaration Information .indent[ Thursday, January 29th at 4pm in Noyce 3821 ] --- class: section blue # Upcoming Work --- # Week 1 Lab Report *Due tonight at 10:00pm* Upload `partC.c` from Thursday's lab to the assignment on Gradescope. You do not need to submit any other work you completed for the labs last week. Make sure you add your lab partner(s) when you submit so everyone receives credit. ## Code Style Requirements - Use consistent indentation for code inside `main`. - *That's it for now!* --- # Week 2 Quiz As usual, we'll have a quiz on Thursday. The quiz will last 10 minutes, and could cover any of these new topics: 1. Conditionals (`if`, `else if`, `else`, and `switch`-`case`) 2. Loops (`while`, `do`-`while`, and `for`) 3. Function Basics (from Thursday's reading) -- In general, you should expect weekly quizzes to include at least one question from the reading assigned for that day. Questions about topics from Thursday's reading will get at surface-level information, not complex applications. -- Quizzes will inevitably include material from earlier weeks, so don't be surprised if you see a variable or expression on the quiz this week. -- You should be prepared to write code out by hand on quizzes. Syntax is less important than demonstrating understanding, but do your best to get the syntax close. --- class: section blue # Discussion --- # Discussion: Conditionals **Items for think, pair, share:** 1. What is the difference between the `==` and `=` operators? 2. Do all `if` statements need a corresponding `else` in C? 3. What does the C expression `a ? b : c` do? 4. What is the purpose of a `break` statement inside a `switch` block? --- # Discussion: Loops **Items for think, pair, share:** 1. What is the difference between a `while` loop and a `do`-`while` loop? 2. What do `break` and `continue` do inside a loop? 3. Convert this `for` loop into an equivalent `while` loop: ```c for (int i = 0; i < 10; i++) { printf("i is %d\n", i); } ``` --- # Reading Questions Do you have any unanswered questions from the reading? --- class: section blue # Code Style --- # Code Style Revised code style guidelines for new work as of today: -- 1. Indent code within `{}` braces one level deeper than the surrounding code. -- 2. Always use `{}` braces for `if`, `else`, `switch`, and all loops. ***Always.*** -- 3. Use consistent brace style. I usually use same-line braces: ```c if (a == 1) { ... } else { ... } ``` -- 4. Write at least one `//` comment before each loop or block of conditionals. Explain what the block below it is meant to do. -- 5. Use descriptive variable names. -- 6. Declare variables close to where you use them, and in the smallest scope possible. --- class: section green # Lab --- # Lab: Tips 1. Do your lab work on MathLAN machines, not your personal computer. Your partner(s) should feel just as comfortable using the computer as you are. 2. The lab suggests looking at `man` pages for functions. Not everything in these pages will make sense yet, but they can still be helpful. When you're done reading a manpage, type **q** to quit. --- class: section blue # Wrap Up --- # Wrap Up ## Lab Work You will need to submit your completed `rps.c` implementation with this week's lab report. You'll also build on this implementation on Thursday so if you have a lot of work left you should try to make some progress before Thursday if possible. -- ## Getting Help Are you falling behind or feeling confused about course content? There are resources to help: - My office hours (book at
) - Mentor sessions (Wednesdays from 7–9pm) - Evening tutors (Almost every day in Noyce 3813 and 3815) -- ## Reading - **Functions** (Beej's Guide to C Programming, Chapter 4)