Navigation



6.1 — Arrays (Part I)

In a previous lesson, you learned that you can use structs to aggregate many different data types into one variable. However, structs are not the only aggregate data type. An array is an aggregate data type that lets you access multiple variables through a single name by use of an index. In C++, all . . . → Read More: 6.1 — Arrays (Part I)

5.8 — Break and continue

Break

Although you have already seen the break statement in the context of switch statements, it deserves a fuller treatment since it can be used with other types of loops as well.

The break statement causes a switch statement, while loop, do while loop, or for loop to terminate. In the context of a . . . → Read More: 5.8 — Break and continue

5.7 — For statements

By far, the most utilized looping statement in C++ is the for statement. The for statement is ideal when we know exactly how many times we need to iterate, because it lets us easily declare, initialize, and change the value of loop variables after each iteration.

The for statement looks pretty simple:

for (init-statement; . . . → Read More: 5.7 — For statements

5.6 — Do while statements

One interesting thing about the while loop is that if the loop condition is false, the while loop may not execute at all. It is sometimes the case that we want a loop to execute at least once, such as when displaying a menu. To facilitate this, C++ offers the do while loop:

do . . . → Read More: 5.6 — Do while statements

Six language-independent ways to write better code

One of the amazing things about working in a department with other coders is that you consistently see the same mistakes being made day after day, month after month, year after year. Whether it’s due to general timidity, fear of criticism being taken personally, lack of a formal review process, or a company . . . → Read More: Six language-independent ways to write better code