百科问答小站 logo
百科问答小站 font logo



在编程语言中,循环语句为何选择 while 而不是 when 作为关键词? 第1页

  

user avatar   mai-wen-xue-67 网友的相关建议: 
      

这是英语惯用法(USAGE)和逻辑的问题。


WHEN 标志一个时刻或者时间点,

WHILE 标志一个时间段。

如果您查一下字典, 就不会再有这样的疑惑。



       美国传统词典[双解] while while AHD:[hwīl, wīl] D.J.[hwaIl, waIl] K.K.[hwaIl, waIl] n.(名词) A period of time: 一段时间: stay for a while; sang all the while.See Usage Note at awhile 停留下会儿;一直都在唱歌参见 awhile The time, effort, or trouble taken in doing something: 费时:做一件事情的花费时间、努力或工夫: The project wasn't worth my while. 这项方案不值得我花工夫, conj.(连接词) As long as; during the time that: 只要;在…时间里: It was lovely while it lasted. 当它开着的时间它是很惹人喜爱的 At the same time that; although: 在…同时;尽管,虽然: While the grandparents love the children, they are strict with them. “虽然祖父母们都爱他们的孩子,但却对他们要求严格” Whereas; and: 然而;而,而且: The soles are leather, while the uppers are canvas. 鞋跟是皮的,而鞋面是帆布的, v.tr.(及物动词) whiled,whil.ing,whiles To spend (time) idly or pleasantly: 消磨:闲散或轻松地消磨时间: while the hours away. 消磨时光 <语源> Middle English 中古英语 from Old English hwºl * see  k weiə- 源自 古英语 hwºl *参见 k weiə-  Merriam-Webster's Collegiate 11th Ed. (En-En)   while I.  ˈhwī(-ə)l, ˈwī(-ə)l noun Etymology: Middle English, from Old English hwīl; akin to Old High German hwīla time, Latin quies rest, quiet Date: before 12th century 1.  : a period of time especially when short and marked by the occurrence of an action or a condition : time  stay here for a while 2.  : the time and effort used (as in the performance of an action) : trouble  worth your while II. conjunction Date: 12th century 1.  a.  : during the time that  take a nap while I'm out b.  : as long as  while there's life there's hope 2.  a.  : when on the other hand : whereas  easy for an expert, while it is dangerous for a novice b.  : in spite of the fact that : although  while respected, he is not liked 3.  : similarly and at the same time that  while the book will be welcomed by scholars, it will make an immediate appeal to the general reader — British Book News III. preposition Date: 15th century  dialect British  : until IV. transitive verb (whiled ; whil·ing) Date: 1635  : to cause to pass especially without boredom or in a pleasant manner — usually used with away  while away the time  Oxford Advanced Learner's Dictionary 8th Ed.   while  while  [while whiles whiled whiling]  conjunction,  noun,  verb BrE  [waɪl]  NAmE  [waɪl]   conjunction  (also  formal  whilst  BrE  [waɪlst] ; NAmE  [waɪlst]   especially in BrE) 1. during the time that sth is happening Syn:   ↑when •  We must have been burgled while we were asleep.  •   Her parents died while she was still at school.  •  While I was waiting at the bus stop, three buses went by in the opposite direction.  2. at the same time as sth else is happening •  You can go swimming while I'm having lunch.  •  shoes mended while you wait      


       美国传统词典[双解] when  when AHD:[hwěn, wěn] D.J.[hwen, wen] K.K.[hwɛn, wɛn] adv.(副词) At what time: 什么时候: When will we leave? 我们什么时候离开? conj.(连接词) At the time that: 在…的时候: in the spring, when the snow melts. 在春天,当雪融化的时候 As soon as: 一…就…: I'll call you when I get there. 我一到那里就给你打电话 Whenever: 无论什么时候: When the wind blows, all the doors rattle. 只要风一吹,这门就吱嘎作响 During the time at which; while: 在…期间,当…时: When I was young, I was sick all the time. 在我小时候我总是生病 Whereas; although: 虽然,尽管: She stopped short when she ought to have continued. 尽管她应该继续下去,她却突然停住了 Considering that; if: 考虑到,如果: How can he get good grades when he won't study? 他不用功的话怎么拿高分呢? pron.(代词) What or which time: 什么时候: Since when has this been going on? 从什么时候起事情象这样? n.(名词) The time or date: 时间或日期: Have they decided the where and when? 他们已经定下来地点和时间了吗? <语源> Middle English 中古英语 from Old English hwenne * see  k wo- 源自 古英语 hwenne *参见 k wo- <用法> In informal stylewhen  is often used after be  in definitions: A dilemma is when you don't know which way to turn.   The construction is useful,but it is widely regarded as incorrect or as unsuitable for formal discourse.In formal style there is no alternative but to rephrase such definitions to avoidis when : A dilemma is a situation in which you don't know which way to turn. You are in a dilemma when you don't know which way to turn. 在非正式文体中when 常在定义中用在 be 后面: 进退两难就是当你不知道该走哪条路的时候。  这个结构是有用的,但被广泛认为它对正式交谈来说是不正确的或者是不合适的。在正式文体中没有替代词,只能改变措辞以避免is when : 进退两难就是这样一个你不知道该怎么办的处境。 当你不知道你该做什么时你就处于进退两难的维谷了     



用 WHILE 应该是为了和“持续性”相匹配吧。



举例


备份笔记


       # #  麦文学瞎编的 DATASINK    #  授权: WTFPL #  请随意扩散和使用 # #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <assert.h>  // add this for assert() #include <crtdbg.h> // add this for assert()    size_t SaveFloatBuff(FILE *fp, double *fa, size_t ds_len) {     size_t bufflen = 33554432; //1024*1024*32;     size_t ret = 0;     size_t k = ds_len;      // for (int j=0; j< 256; j = j+8)     // {     //   //printf ("%lf 	%lf 	%lf 	%lf 	%lf 	%lf 	%lf 	%lf 
 ",      //   printf ("%f 	%f 	%f 	%f 	%f 	%f 	%f 	%f
 ",      //   fa[j] , fa[j+1] , fa[j+2] , fa[j+3] , fa[j+4]      //   , fa[j+5] , fa[j+6] , fa[j+7]  );     // }       // Split DATA to write, WHEN ARRAY IS HUGE AS GB OR TB       if (ds_len > bufflen)     {         do{             if ( k >= bufflen )                 {                     ret += fwrite (fa+(ds_len-k), sizeof(double),bufflen , fp);                      if (fwrite != 0) printf("Data to file OK! 	%lld FLOATs Written, #%lld 
"                     , bufflen,  k/bufflen);                      else printf("Error Occured!
");                      k = k - bufflen;                  }              else                  {                     ret += fwrite (fa+(ds_len-k),  sizeof(double), k, fp);                      if (fwrite != 0) printf("Data to file OK! 	%lld FLOAT(s) Written, #%d 
", k,  0);                      else printf("Error Occured!
");                      k = 0;                  }              } while (k >0);              } else       {         ret = fwrite (fa, sizeof(double), ds_len, fp);          if (fwrite != 0) printf("Data to file OK! 	%lld FLOATs written.
", ds_len);          else printf("Error occured!
");      }      return ret; }    int main (){      FILE *outfile = NULL;      double *tmp_arr = NULL;     size_t StreamLen;            // open file to write      outfile = fopen ("rawf_my.dat", "wb");      if (outfile == NULL)      {          fprintf(stderr, "
Error opening file! 
");          exit (1);      }      assert(outfile);     fclose (outfile);       StreamLen = 1024*(1024*1024) + 768*(1024*1024) + 1; //65*(1024*1024);       //1*1024*(1024*1024); //16*(1024*1024)  ;      tmp_arr = (double *) malloc ( StreamLen*sizeof(double) ) ;     if (!tmp_arr) { perror("malloc error: tmp_arr"); exit(EXIT_FAILURE); };      // Gen testing pattern     for (size_t i=0; i< StreamLen; i++)     {       tmp_arr [i] =  (double)  i/(i+1.0) ;      }       outfile = fopen ("rawf_my.dat", "ab");          if (outfile == NULL)          {              fprintf(stderr, "
Error opening file! 
");              exit (1);          }      assert(outfile);      size_t m_ret = SaveFloatBuff(outfile, tmp_arr, StreamLen);     printf("main(): Return code: %lld bytes. 
", m_ret*sizeof(double));      fclose (outfile);      //Sleep(100);     free(tmp_arr);       return 0;  }     


       C:00>write_double_array_split_dowhile_done_msvc_x64.exe Data to file OK!        33554432 FLOATs Written, #56 Data to file OK!        33554432 FLOATs Written, #55 Data to file OK!        33554432 FLOATs Written, #54 Data to file OK!        33554432 FLOATs Written, #53 Data to file OK!        33554432 FLOATs Written, #52 Data to file OK!        33554432 FLOATs Written, #51 Data to file OK!        33554432 FLOATs Written, #50 Data to file OK!        33554432 FLOATs Written, #49 Data to file OK!        33554432 FLOATs Written, #48 Data to file OK!        33554432 FLOATs Written, #47 Data to file OK!        33554432 FLOATs Written, #46 Data to file OK!        33554432 FLOATs Written, #45 Data to file OK!        33554432 FLOATs Written, #44 Data to file OK!        33554432 FLOATs Written, #43 Data to file OK!        33554432 FLOATs Written, #42 Data to file OK!        33554432 FLOATs Written, #41 Data to file OK!        33554432 FLOATs Written, #40 Data to file OK!        33554432 FLOATs Written, #39 Data to file OK!        33554432 FLOATs Written, #38 Data to file OK!        33554432 FLOATs Written, #37 Data to file OK!        33554432 FLOATs Written, #36 Data to file OK!        33554432 FLOATs Written, #35 Data to file OK!        33554432 FLOATs Written, #34 Data to file OK!        33554432 FLOATs Written, #33 Data to file OK!        33554432 FLOATs Written, #32 Data to file OK!        33554432 FLOATs Written, #31 Data to file OK!        33554432 FLOATs Written, #30 Data to file OK!        33554432 FLOATs Written, #29 Data to file OK!        33554432 FLOATs Written, #28 Data to file OK!        33554432 FLOATs Written, #27 Data to file OK!        33554432 FLOATs Written, #26 Data to file OK!        33554432 FLOATs Written, #25 Data to file OK!        33554432 FLOATs Written, #24 Data to file OK!        33554432 FLOATs Written, #23 Data to file OK!        33554432 FLOATs Written, #22 Data to file OK!        33554432 FLOATs Written, #21 Data to file OK!        33554432 FLOATs Written, #20 Data to file OK!        33554432 FLOATs Written, #19 Data to file OK!        33554432 FLOATs Written, #18 Data to file OK!        33554432 FLOATs Written, #17 Data to file OK!        33554432 FLOATs Written, #16 Data to file OK!        33554432 FLOATs Written, #15 Data to file OK!        33554432 FLOATs Written, #14 Data to file OK!        33554432 FLOATs Written, #13 Data to file OK!        33554432 FLOATs Written, #12 Data to file OK!        33554432 FLOATs Written, #11 Data to file OK!        33554432 FLOATs Written, #10 Data to file OK!        33554432 FLOATs Written, #9 Data to file OK!        33554432 FLOATs Written, #8 Data to file OK!        33554432 FLOATs Written, #7 Data to file OK!        33554432 FLOATs Written, #6 Data to file OK!        33554432 FLOATs Written, #5 Data to file OK!        33554432 FLOATs Written, #4 Data to file OK!        33554432 FLOATs Written, #3 Data to file OK!        33554432 FLOATs Written, #2 Data to file OK!        33554432 FLOATs Written, #1 Data to file OK!        1 FLOAT(s) Written, #0 main(): Return code: 15032385544 bytes.  C:00>     



/////////////////////////////////////////////////////////////////////////

看看这个话痨答主有啥其他奇葩崩坏魔愣回答:

..

不用谢。没钱给的话请点个赞,有钱的话请不妨解囊。




  

相关话题

  如何避免完美主义倾向,以应用的方式/目的学习各类理论? 
  码农们最常说的「谎言」有哪些? 
  怎么在事先未知将要输入数字的个数的情况下,将其全部赋值给一个数组? 
  0基础开始,Leetcode200道题要多久左右? 
  为什么 Dropbox 等大型服务使用 Python 作为主要语言,即使它的效率比其他编译型语言低几个数量级? 
  win7笔记本,外接扩展显示器,如何在不缩小外接显示器像素的同时去除外接显示器的桌面背景黑边? 
  很多人说 C++ 的 MFC 已经过时了,那新入门的人到底应该学什么? 
  请问,此题使用switch语句编写是否会比if更高效?若想用switch又该如何编写呢? 
  对于一个开源 Python 量化交易平台项目的建议有哪些? 
  请问是条件状语,还是方式状语? 

前一个讨论
当数学家刚想出微积分用细矩形面积的和逼近时,矩形的高选取多少呢?为何不怕无限多个小误差之和为大误差?
下一个讨论
耳机插进电脑,感觉左耳正常,右耳声音小,换个耳机还是一样,是什么问题?(电脑声音设置都没问题)?





© 2024-11-05 - tinynew.org. All Rights Reserved.
© 2024-11-05 - tinynew.org. 保留所有权利