'F' → Fullscreen
Everything today goes in a new program named 1-19-for.
How to read the code blocks. Each task's code block shows your whole program, from line 1, as it should look when that task is finished.
The green lines marked with a + are the ones you add or change for that task — everything else is already in your file. Do not type the + sign.
Where a block shows only comments, you write that code yourself. The comments stay in your file.
i <= 5 to i < 5 and run it again. Count the lines. One character, one fewer pass.<= before you continue.for (int i = 1; i <= 5; i++){ Console.WriteLine($"Checking system {i}");}
Console.WriteLine("All systems checked.");i-- for the change and >= for the condition. Predict what happens if you write i-- and leave the condition as <=, write the prediction down, and only then run it. The deck already gave you everything you need to get this right.total is declared before its loop, on purpose. Be ready to say what would go wrong inside.for (int i = 1; i <= 5; i++){ Console.WriteLine($"Checking system {i}");}
Console.WriteLine("All systems checked.");Console.WriteLine();
int total = 0;
for (int i = 1; i <= 10; i++){ total = total + i;}
Console.WriteLine($"Sum of 1 to 10: {total}");Console.WriteLine();
for (int i = 10; i >= 1; i--){ Console.WriteLine($"T-minus {i}");}total was in Task 2.for (int i = 1; i <= 5; i++){ Console.WriteLine($"Checking system {i}");}
Console.WriteLine("All systems checked.");Console.WriteLine();
int total = 0;
for (int i = 1; i <= 10; i++){ total = total + i;}
Console.WriteLine($"Sum of 1 to 10: {total}");Console.WriteLine();
for (int i = 10; i >= 1; i--){ Console.WriteLine($"T-minus {i}");}
Console.WriteLine();
// Ask how many crates to load and convert the answer// Loop that many times, showing the crate number each pass// Keep a running total of mass, adding 40 for every crate// After the loop, display the total massTwo changes, one at a time. Write down exactly what happens, and put each one back before you try the next.
i-- to i++ and leave everything else alone. Run it, watch for a moment, then press Ctrl + C.Console.WriteLine(i); as the very last line of your program and try to run it.For number 1, record what it printed and how you stopped it. For number 2, record the error code, the message, and the line number — copy them exactly.
Number 2 never ran at all, and that is the difference worth noticing. Number 1 was a program that worked exactly as written and was still wrong. Number 2 was refused before it started. Say which kind of mistake is easier to find.
The reference sheet has no for loop at all. It offers REPEAT n TIMES, REPEAT UNTIL from Activity 1.17, and one more you meet at Activity 1.25. That is the complete set.
for (int i = 1; i <= 5; i++){ Console.WriteLine(i);}i ← 1
REPEAT 5 TIMES{ DISPLAY(i) i ← i + 1}REPEAT n TIMES gives you no counter. It repeats a block a fixed number of times and tells the block nothing at all about which pass it is on.
So when the block needs the pass number, you build the counter by hand — declared before the loop, and moved along as the last line inside it. Two extra lines of housekeeping that C# packs into one header.
| C# | Exam notation |
|---|---|
for (int i = 1; i <= 5; i++) | REPEAT 5 TIMES, plus a counter by hand |
for (int i = 1; i <= n; i++) | REPEAT n TIMES, plus a counter by hand |
while (fuel < 500) | REPEAT UNTIL(fuel ≥ 500) |
REPEAT, and an i ← i + 1 at the bottom of the block is one of the most common patterns on the whole exam.i is available. If a question uses REPEAT n TIMES and declares no counter, the block genuinely cannot tell which pass it is on, and a question may be testing exactly that.REPEAT n TIMES.Your finished program should run like this.
Checking system 1Checking system 2Checking system 3Checking system 4Checking system 5All systems checked.
Sum of 1 to 10: 55
T-minus 10T-minus 9T-minus 8T-minus 7T-minus 6T-minus 5T-minus 4T-minus 3T-minus 2T-minus 1
How many crates? 3 [Enter]Crate 1 loadedCrate 2 loadedCrate 3 loadedTotal mass: 120<= to <Answer the following questions before submitting your work.
for loop and a while loop can do the same job, and today's first slide proved it. Explain when each one is the clearer choice, and why gathering the three parts into one line makes a certain mistake harder to make.i <= 5 and i < 5 differ by one character and by one pass. Explain why that is such an easy mistake to make and how you would catch it in your own code.for loop, so the counter has to be maintained by hand. Describe what would go wrong if the i ← i + 1 were placed at the top of the block instead of the bottom.Submit four things to the dropbox: