Linux [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Linux [Electronic resources] - نسخه متنی

Janet Valade

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Infinite Loops


Loops can be infinite loops. That is, loops that continue repeating forever. Infinite loops are seldom written deliberately. They usually result from a scripting error. No one is immune.

The following program results in an infinite loop:

#!/bin/bash
while [ $n -lt 10 ]
do
n=0
echo $n
let n=$n+1
done

The output from this program is:

0
0
0
0
...

continuing forever because $n is set to 0 at the beginning of each loop. Therefore, $n will never become equal to 10. So, the loop will never stop.

Another common scripting mistake is to leave out the statement that increments the value being tested. For instance, if you left out the let command in the above script, you would create an infinite loop.

You can stop an infinite loop with <Ctrl-c>. Perhaps more than one <Ctrl-c>. It should break out of the script. Also, a <Ctrl-z> works. It stops the script. Sometimes the output will continue to display for a time, but it will stop shortly.


    / 357