www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - no print function output do while

reply dark777 <jeanzonta777 yahoo.com.br> writes:
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
Sep 28
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Sep 28
parent reply dark777 <jeanzonta777 yahoo.com.br> writes:
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); } }
Sep 28
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Sep 28
parent reply arturg <var.spool.mail700 gmail.com> writes:
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; ... } }
Sep 28
parent dark777 <jeanzonta777 yahoo.com.br> writes:
On Thursday, 28 September 2017 at 21:34:46 UTC, arturg wrote:
 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; ... } }
It's good that it worked out here.
Sep 28