Fixed some typos in while and for pages
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@223 a672b425-5310-4d7a-af5c-997e18724b81
This commit is contained in:
parent
2bc4e0401b
commit
0d08db098f
1 changed files with 8 additions and 8 deletions
|
@ -41,10 +41,10 @@ done
|
|||
{% endhighlight %}
|
||||
|
||||
In this first example, you simply create a variable called i and evaluate it to 0.
|
||||
Then you access the while loop: the condition <code> [$i -lt 4] </code> means that this while
|
||||
loop will run until the <code> i </code> variable is less than 4.
|
||||
Every cycle of this loop, you print out the value of variable i with <code> echo $i </code>
|
||||
and finally, you increase its value by 1 with <code> i=$((i + 1)) </code>.
|
||||
Then you access the while loop: the condition <code> [$i -lt 4]</code> means that this while
|
||||
loop will run until the <code> i</code> variable is less than 4.
|
||||
Every cycle of this loop, you print out the value of variable i with <code> echo $i</code>
|
||||
and finally, you increase its value by 1 with <code> i=$((i + 1))</code>.
|
||||
Therefore in 4 cycles the value of i will be 4. This will make the condition of the while loop false.
|
||||
The output of this piece of code is:
|
||||
<pre>
|
||||
|
@ -80,9 +80,9 @@ done
|
|||
|
||||
No termination condition is set for this loop in this example. This type of loop
|
||||
is called infinite loop.<br>
|
||||
The <code> exit </code> statement is used to quit the loop. This loop will
|
||||
The <code> exit</code> statement is used to quit the loop. This loop will
|
||||
iterate for 9 times, then
|
||||
as soon as <code> i </code> becomes equal to 0, the condition of the last if
|
||||
as soon as <code> i</code> becomes equal to 0, the condition of the last if
|
||||
statement will evaluate to true and the loop will be terminated. <br>
|
||||
|
||||
The output of this piece of code is:
|
||||
|
@ -124,11 +124,11 @@ done < "$file"
|
|||
{% endhighlight %}
|
||||
|
||||
The <code> read </code> command is used to read a file line by line.
|
||||
The flag <code> -r </code> is used to tell the
|
||||
The flag <code> -r</code> is used to tell the
|
||||
command read to interpret backslashes (/) literally, instead as escape characters.
|
||||
This command, expect for some few
|
||||
rare cases, should always be used with this flag.
|
||||
In this example, <code> < "$file" </code> redirects the loop's input from a file
|
||||
In this example, <code> < "$file"</code> redirects the loop's input from a file
|
||||
whose name is stored in a variable.
|
||||
This file has 3 columns, <code> first_name last_name phone </code>, separated by
|
||||
blank space (or a tab).
|
||||
|
|
Loading…
Reference in a new issue