2016년 11월 16일 수요일

while sentence

while sentence

while sentence is a sentence to describe a loop repeating the practice of the sentence that a condition was given only during the truth (logic level :true, numerical value: a value except 0 including 1) in a programming language.

The description of the loop has two of a preliminary remark judgment and the postposition judgment. The preliminary remark judgment evaluates the condition type first and performs the processing in the loop if it is the truth. while (expression) {sentence} becomes the preliminary remark judgment by the C language. The postposition judgment processes the loop first and performs a condition-style evaluation afterwards. Similarly, is C; do {sentence} while (expression), But, it becomes the postposition judgment. If a condition is a false in the preliminary remark judgment (logic level :false, numerical value: 0), the difference of neither never performs the processing in the loop; correspond, and, as for at least one time, there is the processing of loops in the postposition judgment at a performed point.

Table of contents

Grammar

In the case of a language to be similar to C and it, I it

The basic sentence structure is as follows in C, C++, C#, D, JAVA, perl.

 while (condition) {     Sentence } 

This loop is carried out in the following procedure.

  1. I evaluate a condition. If a condition is false, I finish a loop.
  2. I carry out a truth sentence.
  3. I return to the evaluation of the condition.

When a condition is false from the beginning, the truth sentence will be never carried out.

The while sentence of the C language can renew initialization and the update of the counter variable as the for sentence that I omitted. Therefore, it may be said that the while sentence of the C language specialized for sentence. But the point that cannot omit the condition of the loop is different from for sentence in the while sentence.

Example sentence

 int x = 0, while (x <100) {     printf("x is %d.\n",x),     x++; } 

The following output result is provided when I carry this out.

 x is 0. x is 1.  …………   x is 98. x is 99. 

A value of beginning variable x is 0, and 1 is added whenever one time of truth sentence is carried out. Because the value of x becomes 100 when 100 times of truth sentences are carried out, and a condition does not hold good, this loop is finished then.

There is the method to use the break sentence in a truth sentence unless I make the condition of the loop a false to finish a loop. When conditions of the loops are always the truth, and break sentence is not included in a truth sentence (when or break sentence is not carried out), the loop becomes the infinite loop. In addition, when a truth sentence consists of plural sentences, I cancel the practice of the truth sentence by using the continue sentence and can reopen processing from the evaluation of the condition.

In the case of Pascal, I it

In Pascal, I use repeat, until as a postposition judgment as a preliminary remark judgment again in while, do.

Preliminary remark judgment

 while condition do sentence 

Postposition judgment

 repeat sentence, Sentence...; Sentence until condition 

While a condition type is false, in repeat-until, it processes the loop, and the point that passes through the loop when it becomes truly is different from do-while such as C. Unlike while, I can put plural sentences as needed between repeat and until.

In the case of Visual Basic, I it

In Visual Basic, I use Do as a postposition judgment as a preliminary remark judgment for a condition to continue a loop between the truth in While, Do While.

Preliminary remark judgment by While

 While condition     Sentence Wend 

Preliminary remark judgment by Do While

 Do While condition     Sentence Loop 

Postposition judgment by Do

 Do     Sentence Loop While condition 

While a condition is false, in Visual Basic, I can continue a loop regardless of a preliminary remark judgment, a postposition judgment. I use Do as Do Until, a postposition judgment as a preliminary remark judgment. But, unlike While, Until without Do is not available.

False preliminary remark judgment by the Do While sentence

 Do Until condition     Sentence Loop 

False postposition judgment by the Do sentence

 Do     Sentence Loop Until condition 

Allied item

This article is taken from the Japanese Wikipedia while sentence

This article is distributed by cc-by-sa or GFDL license in accordance with the provisions of Wikipedia.

Wikipedia and Tranpedia does not guarantee the accuracy of this document. See our disclaimer for more information.

In addition, Tranpedia is simply not responsible for any show is only by translating the writings of foreign licenses that are compatible with CC-BY-SA license information.

0 개의 댓글:

댓글 쓰기