no print function output do while

arturg var.spool.mail700 at gmail.com
Thu Sep 28 21:34:46 UTC 2017


On Thursday, 28 September 2017 at 20:17:24 UTC, Ali Çehreli wrote:
> On 09/28/2017 12:18 PM, dark777 wrote:
>> On Thursday, 28 September 2017 at 18:46:56 UTC, Ali Çehreli 
>> wrote:
>>> On 09/28/2017 08:13 AM, dark777 wrote:
>>>> no print function output do while
>>>>
>>>> in my program after entering the data and select the 
>>>> function that will print on the screen the same is not 
>>>> printing ..
>>>>
>>>> and if I choose 'q' or 'Q' does the program not close what 
>>>> is happening?
>>>> should not it work just like in C ++?
>>>>
>>>> https://pastebin.com/iiMVPk4x
>>>
>>> You made a simple logic error. Change the following || to &&:
>>>
>>>     }while(choice != 'q' || choice != 'Q');
>>>
>>> Ali
>> 
>> I think it should not give this error
>> 
>> good but until now I do not understand why after I enter with 
>> data in the function add_human
>> 
>> the same is not printed when I choose the 'p' or 'P' option in 
>> the case
>> 
>> void print_list(Human[] human_list)
>> {
>>   foreach(human; human_list)
>>     {
>>      writefln("\nNome: %s",human.name);
>>      writefln("Peso: %0.2f",human.peso);
>>      writefln("Idade: %d\n",human.age);
>>     }
>> }
>
> It's because add_human is appending to its own array. Change it 
> to by-ref:
>
> void add_human(ref Human[] human_list)
>
> Ali

while(choice != 'q' || choice != 'Q');
doesn't seem to exit the loop, while this works:
while(choice != 'q');
or
while(!(choice == 'q' || choice == 'Q'));

wouldn't it be better to use a labeled statement instead?

endless : while(true)
{
     ...

     switch(choice)
     {
         ...

         case 'Q':
         case 'q': break endless;

         ...
     }
}


More information about the Digitalmars-d-learn mailing list