You are looking at lesson 3. Your place is still Practice test 2, task 1: About.
while, do-while and for, break and continue, and what to do when a loop never ends.
int i = 1;
while (i <= 3) {
printf("%d\n", i);
i++;
}
While the condition is true, the body { } repeats. The condition is checked before each time, so if it is false from the start, the body doesn't run even once. i++ increases i by one: the same as i = i + 1.
int grade;
do {
grade = read_int("Grade: ");
} while (grade < 1 || grade > 10);
The condition is checked after the body, so the body runs at least once. It fits when you always have to ask, and repeat only if the answer doesn't fit. The ; after while (...) at the end is required.
for (int i = 1; i <= 3; i++) {
printf("%d\n", i);
}
for puts three parts in one line: the start (int i = 1), the condition (i <= 3) and the step (i++). It does the same as the while above. Use it when you know in advance how many times to repeat.
i += 3 is the same as i = i + 3. There are also -=, *= and /=, and i-- decreases by one.int i declared inside for exists only inside the loop. A variable declared inside { } exists until those braces end.break ends the loop at once.continue skips the rest of the body and goes on to the next time round.If the condition never becomes false, the loop spins forever. Most often an i++ is forgotten, or reading a new value inside the loop. In CLion you stop such a program with the red square ■ (Ctrl+F2). On GitHub a time limit cuts the test off after a few seconds.
Each one ticks itself when you do it.
All six done. You know your way around.
It is laid out like CLion: the same panels in the same places. This tour shows each one, and you can reopen it any time with Tour.
Switches the left panel: Lesson plan, Project files, Changes. Click the active icon again to hide the panel.
In CLion: the tool window bar runs down the left edge, too.
This part is not on this task: it appears when a task needs it.
Every task in this lesson. Now marks your place. Clicking a task only lets you look; it never moves your place. Project files and Changes open here too.
In CLion: this spot holds the Project view (the file tree).
This part is not on this task: it appears when a task needs it.
Opens the file for your task by itself. A tab appears for each file the step opens. The breadcrumbs above the code show the folder.
In CLion: the same editor tabs and breadcrumbs.
This part is not on this task: it appears when a task needs it.
Diff shows what changed, like git diff: red is the old code, green the new.
In CLion: the diff view in the Commit window looks the same.
This part is not on this task: it appears when a task needs it.
Terminal for build commands, Database to see your tables. They open by themselves when a task needs them. Drag the top edge to resize.
In CLion: Terminal, and the Database tool window.
This part is not on this task: it appears when a task needs it.
What to do now, right above the code, so you never miss it. Numbered notes in the code explain the important lines. Details shows what you should see and a hint.
In CLion: no equivalent: this is your lecturer's guide.
This part is not on this task: it appears when a task needs it.
Done is the only button that moves you forward. Look back lets you review without losing your place.
This part is not on this task: it appears when a task needs it.
Guided, Focus code or Floating. You can drag the panel edges too. Your layout is remembered for next time.
In CLion: you can also rearrange and hide tool windows.
This part is not on this task: it appears when a task needs it.
Six small missions. Each one ticks itself when you do it, so you know you have found everything.