R, How does while (TRUE) work?

前端 未结 2 1740
长情又很酷
长情又很酷 2021-02-15 12:32

I have to write a function of the following method :

Rejection method (uniform envelope):

Suppose that fx is non-zero only on [a, b], and fx ≤ k.

2条回答
  •  孤城傲影
    2021-02-15 13:06

    Inside while loop, if we have return statement with true or false.. it will work accordingly..

    Example: To Check a list is circular or not..

    here the loop is infinite, because while (true) is true always, but we can break sometimes by using the return statement,.

    while(true)
    {
    if(!faster || !faster->next)
    return false;
    else
    if(faster==slower || faster->next=slower)
    {
    printf("the List is Circular\n");
    break;
    }
    else
    {
    slower = slower->next;
    faster = faster->next->next;
    }
    

提交回复
热议问题