The other main type of control statement is the loop. Loops allow a statement, or block of statements, to be repeated. Computers are very good at repeating simple tasks many times. The loop is C's way of achieving this.

Data Recovery PRO DATA DOCTOR

Home | Order Online | Downloads | Contact Us | Software Knowledgebase

it | es | pt | fr | de | jp | kr | cn | ru | nl | gr


Loops

The other main type of control statement is the loop. Loops allow a statement, or block of statements, to be repeated. Computers are very good at repeating simple tasks many times. The loop is C's way of achieving this.

C gives you a choice of three types of loop, while, do-while and for.

  • The while loop keeps repeating an action until an associated test returns false. This is useful where the programmer does not know in advance how many times the loop will be traversed.
  • The do while loops is similar, but the test occurs after the loop body is executed. This ensures that the loop body is run at least once.
  • The for loop is frequently used, usually where the loop will be traversed a fixed number of times. It is very flexible, and novice programmers should take care not to abuse the power it offers.

The while Loop

The while loop repeats a statement until the test at the top proves false. As an example, here is a function to return the length of a string. Remember that the string is represented as an array of characters terminated by a null character '\0'.

int string_length(char string[])
{ int i = 0;

while (string[i] != '\0')
i++;

return(i);
}

The string is passed to the function as an argument. The size of the array is not specified, the function will work for a string of any size.

The while loop is used to look at the characters in the string one at a time until the null character is found. Then the loop is exited and the index of the null is returned.

While the character is not null, the index is incremented and the test is repeated. We’ll go in depth of arrays later. Let us see an example for while loop:

#include <stdio.h>

int main()
{
int count;

count = 0;

while (count < 6)
{
printf("The value of count is %d\n", count);
count = count + 1;
}

return 0;
}

and the result is displayed as follows:

The value of count is 0
The value of count is 1
The value of count is 2
The value of count is 3
The value of count is 4
The value of count is 5


Sample Chapters from book DATA RECOVERY WITH AND WITHOUT PROGRAMMING by Author Tarun Tyagi
Data Recovery with & without Programming


Publishers of the Book
Number of Pages
ISBN
Price of the Book


BPB Publications, New Delhi, India
540
81-7656-922-4
$69.00 (Including Shipping Charges, Cost of Book and Other expenses, Free Source Code CD included with the Book)





Buy Data recovery Book

Previous page

page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20

 
 

page 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37

 
 

page 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54

 
 

page 55 | 56 | 57 | 58 | 59 | 60

Next page

© Copyright 2002-2005 DataDoctor.Biz

Home | Contact us | Downloads | Services | Terms and conditions | Site map

Website Data Recovery | recuperación de Datos | Récupération de données | Datenrettung | Recupero dati | データ復旧 | 데이터 복구 | 数据恢复 | Восстановление данных | De terugwinning van gegevens | Ανάκτηση δεδομένων
Sitemap Site map1 2 3 4 | Spanish1 2 3 | French1 2 3 | German1 2 3 | Italian1 2 3 | Portuguese1 2 3 | Japanese1 2 3 | Korean1 2 3 | Chinese1 2 3 | Russian1 2 3 | Dutch1 2 3 | Greek1 2 3
Data Recovery Book English | Spanish | French | German | Italian | Portuguese | Japanese | Korean | Chinese | Russian | Dutch | Greek