什么是FOR TO DO語句的變量和循環
這東西沒必要解釋的吧。
for i := 5 to 10 do
writeln(i);
這個展開就是
i:= 5;
writeln(i);
i:= 6;
writeln(i);
。.
i:= 10;
writeln(i);
pascal里的for循環,循環變量一定是每次增1或減1的。
to/downto 左邊是初值,右邊是終值,to的話就是+1,downto就是-1
用begin..end包裹,那是表示一個語句塊,因為按規定for語句后只能有一條執行語句,當有多條語句的時候就必須有begin。end來包裹這些語句。
to與for在句子中的區別to和for后都可加地點,如
for有很多種用法: 1. 表示“當作、作為”.如: I like some bread and milk for breakfast. 我喜歡把面包和牛奶作為早餐. What will we have for supper? 我們晚餐吃什么? 2. 表示理由或原因,意為“因為、由于”.如: Thank you for helping me with my English. 謝謝你幫我學習英語. Thank you for your last letter. 謝謝你上次的來信. Thank you for teaching us so well. 感謝你如此盡心地教我們. 3. 表示動作的對象或接受者,意為“給……”、“對…… (而言)”.如: Let me pick it up for you. 讓我為你撿起來. Watching TV too much is bad for your health. 看電視太多有害于你的健康. 4. 表示時間、距離,意為“計、達”.如: I usually do the running for an hour in the morning. 我早晨通常跑步一小時. We will stay there for two days. 我們將在那里逗留兩天. 5. 表示去向、目的,意為“向、往、取、買”等.如: Let's go for a walk. 我們出去散步吧. I came here for my schoolbag.我來這兒取書包. I paid twenty yuan for the dictionary. 我花了20元買這本詞典. 6. 表示所屬關系或用途,意為“為、適于……的”.如: It's time for school. 到上學的時間了. Here is a letter for you. 這兒有你的一封信. 7. 表示“支持、贊成”.如: Are you for this plan or against it? 你是支持還是反對這個計劃? 8. 用于一些固定搭配中.如: Who are you waiting for? 你在等誰? For example, Mr Green is a kind teacher. 比如,格林先生是一位心地善良的老師. ---- for與to的區別: In English, prepositions are used to indicate the relations between the predicate and its arguments. For, when used for this purpose, indicates the benefactive relation, i.e. some one who benefits from the event specified by the * TO is used to indicate the dative relation, * goal to which the action is directed. Compare the following two sentences: (a) John gave a gift to his girlfriend. (b) John gave his life for his country. 簡單來說就是,for更注重目的,表示有一方受益,to更注重指向。