Skip to content

Commit 4f56bfc

Browse files
committed
sort out sequence and data concepts
1 parent b491d8e commit 4f56bfc

18 files changed

+288
-1007
lines changed

src/content/docs/book/part-1-instructions/1-sequence-and-data/1-concepts/00-program.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ We use data to capture the information we need the program to work with. The dat
8989
:::note[Summary]
9090

9191
- You can create something the user can run from the program's **source code**.
92-
- Most importantly, you cant really *see* the program in the code. The program is **all** of this code together. It is the container that holds the instructions that will run when it is executed.
92+
- Most importantly, you can't really *see* the program in the code. The program is **all** of this code together. It is the container that holds the instructions that will run when it is executed.
9393
- The program has an **entry point** that indicates where the program’s instructions start - in this case the first instruction.
9494
- Your program can use code from [libraries](../08-library) giving it access to building blocks others have created.
9595
- Data is also central to the program.

src/content/docs/book/part-1-instructions/1-sequence-and-data/1-concepts/03-method-call.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,22 @@ All of the arguments in this code are using literal values.
101101

102102
### Example using result
103103

104-
Some methods return data, which you can use within any calculated value ([expression](../07-expression)) within your code. The following code demonstrates the use of the values returned by the `ColorWhite` and `Rnd` methods.
104+
Some methods return data, which you can use within any calculated value ([expression](../07-expression)) within your code. The following code demonstrates the use of the values returned by the `RandomColor` and `Rnd` methods.
105105

106106
<a id="ListingReturn"></a>
107107

108108
```csharp
109109
using static SplashKitSDK.SplashKit;
110110

111-
OpenWindow("A House", 800, 600);
112-
ClearScreen(ColorWhite());
111+
OpenWindow("Random Color", 800, 600);
112+
ClearScreen(RandomColor());
113113
RefreshScreen();
114114
Delay(1000 * Rnd(10));
115115
```
116116

117117
<div class="caption"><span class="caption-figure-nbr">Listing 5.x: </span>Code demonstrating use of return values.</div>
118118

119-
Line 4 demonstrates the use of the result from calling `ColorWhite` within the call to `ClearScreen`. In this case, the value returned from the `ColorWhite` becomes the value for the argument passed to `ClearScreen`. As you would expect, this will clear the screen to the white color.
119+
Line 4 demonstrates the use of the result from calling `RandomColor` within the call to `ClearScreen`. In this case, the value returned from the `RandomColor` becomes the value for the argument passed to `ClearScreen`. As you would expect, this will clear the screen to a random color.
120120

121121
Line 6 demonstrates this again, the result of `1000 * Rnd(10)` is passed to `Delay`. The easiest way to approach this is to consider each value independently. `Rnd(10)` will return a random value between 0 and 10 - let us imagine this returns `6` so that we can see what that does. In this case, `1000 * Rnd(10)` becomes `1000 * 6`, as the value **returned** by `Rnd(10)` was `6`. This is then evaluated, and `Delay` will be passed the argument `6000`, causing it to delay for 6 seconds.
122122

src/content/docs/book/part-1-instructions/1-sequence-and-data/1-concepts/10-comments.md

Lines changed: 0 additions & 89 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
title: Sequence
33
---
4+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: "Comments"
3+
---
4+
5+
A program's source code contains instructions for the computer to perform. However, this code is written and maintained by people. It is often useful to be able to place comments in the code to help someone reading that code understand how it works or what it is trying to achieve. This text is not something to be translated into machine code, it is for us humans.
6+
7+
Programming languages support the ability to embed *comments* into the source code that are then ignored by the compiler.
8+
9+
## In C#
10+
As stated, comments allow you to embed documentation and explanatory text within your program’s code. The comments are skipped by the compiler, so they have no affect on the program’s machine code. You write comments to help yourself and other people understand what you intend the program to do, and any thoughts you want to record along with the code.
11+
12+
13+
:::tip[Syntax]
14+
15+
<a href="#FigureCommentsSyntax">Figure 5.13</a> shows the syntax for comments in C#. There are two types of comments, single line comments, and block comments that span multiple lines.
16+
17+
- **Block comments** begin with `/*` and end with `*/` and contain any text in between these, including new lines.
18+
- **Single line comment** begin with `//` and end with a new line.
19+
20+
21+
<a id="FigureCommentsSyntax"></a>
22+
23+
![Figure 5.13 The syntax of comments.](./images/program-creation/CommentsSyntax.png "The syntax of comments")
24+
<div class="caption"><span class="caption-figure-nbr">Figure 5.13: </span>The syntax of comments</div><br/>
25+
26+
:::
27+
28+
## Example
29+
30+
Example comments are shown within a code block in <a href="#ListingExampleComments">Listing 5.11</a> below</div>
31+
32+
<a id="ListingExampleComments"></a>
33+
34+
```csharp
35+
/*
36+
* This program calculates the area of a circle based on the radius.
37+
* Variables:
38+
* - the radius as a double
39+
* - the area as a double
40+
* - a line string to read text from the user
41+
*/
42+
43+
using static System.Convert;
44+
using static System.Console;
45+
46+
// Setup constants and variables
47+
const double PI = 3.1415;
48+
string line;
49+
double radius, area;
50+
51+
// Get data from the user
52+
Write("Radius: ");
53+
line = ReadLine();
54+
radius = ToDouble(line);
55+
56+
// Calculate area
57+
area = PI * radius * radius;
58+
59+
// Output area
60+
WriteLine(area);
61+
```
62+
63+
<div class="caption"><span class="caption-figure-nbr">Listing 5.11: </span>Example C# comments</div>
64+
65+
66+
## Activities
67+
68+
1. Is the following a valid comment in C#? Why/why not?
69+
70+
```csharp
71+
/*
72+
/* my comment */
73+
*/
74+
```
75+
76+
<div class="caption"><span class="caption-figure-nbr">Listing 5.12: </span>Sample code</div>
77+
78+
:::note[Summary]
79+
80+
- It is good practice to place a comment at the top of your code explaining what the program does.
81+
- Comments should be included to help other people read your code. You will also find these comments useful when you return to your code after a long break.
82+
- Make your comments meaningful by trying to capture your intentions and ideas
83+
- Comments have no impact on the output produced by the compiler.
84+
85+
:::
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Summary of Program Creation Concepts"
2+
title: "Summary"
33
type: "content"
44
date: 2023-08-07 16:45:00
55
draft: false

src/content/docs/book/part-1-instructions/1-sequence-and-data/1-concepts/25-summary-of-storing-using-data-concepts.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)