digitalmars.D.learn - no print function output do while
- dark777 (7/7) Sep 28 2017 no print function output do while
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/13) Sep 28 2017 You made a simple logic error. Change the following || to &&:
- dark777 (15/29) Sep 28 2017 I think it should not give this error
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/38) Sep 28 2017 It's because add_human is appending to its own array. Change it to by-re...
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 2017
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/iiMVPk4xYou made a simple logic error. Change the following || to &&: }while(choice != 'q' || choice != 'Q'); Ali
Sep 28 2017
On Thursday, 28 September 2017 at 18:46:56 UTC, Ali Çehreli wrote:On 09/28/2017 08:13 AM, dark777 wrote: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); } }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/iiMVPk4xYou made a simple logic error. Change the following || to &&: }while(choice != 'q' || choice != 'Q'); Ali
Sep 28 2017
On 09/28/2017 12:18 PM, dark777 wrote:On Thursday, 28 September 2017 at 18:46:56 UTC, Ali Çehreli wrote:It's because add_human is appending to its own array. Change it to by-ref: void add_human(ref Human[] human_list) AliOn 09/28/2017 08:13 AM, dark777 wrote: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); } }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/iiMVPk4xYou made a simple logic error. Change the following || to &&: }while(choice != 'q' || choice != 'Q'); Ali
Sep 28 2017
On Thursday, 28 September 2017 at 20:17:24 UTC, Ali Çehreli wrote:On 09/28/2017 12:18 PM, dark777 wrote: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; ... } }On Thursday, 28 September 2017 at 18:46:56 UTC, Ali Çehreli wrote:It's because add_human is appending to its own array. Change it to by-ref: void add_human(ref Human[] human_list) AliOn 09/28/2017 08:13 AM, dark777 wrote: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); } }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/iiMVPk4xYou made a simple logic error. Change the following || to &&: }while(choice != 'q' || choice != 'Q'); Ali
Sep 28 2017
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:It's good that it worked out here.On 09/28/2017 12:18 PM, dark777 wrote: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; ... } }On Thursday, 28 September 2017 at 18:46:56 UTC, Ali Çehreli wrote:It's because add_human is appending to its own array. Change it to by-ref: void add_human(ref Human[] human_list) AliOn 09/28/2017 08:13 AM, dark777 wrote: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); } }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/iiMVPk4xYou made a simple logic error. Change the following || to &&: }while(choice != 'q' || choice != 'Q'); Ali
Sep 28 2017