frankcollins3 / fcc-mcsft-cSharp

FreeCodeCamp & Microsoft C# course:
1 stars 0 forks source link

multiple logical && operators in while block statement [10:50am] #14

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: gather input recursively, requesting user enters either: ['admin', 'manager', 'user'] into the input. Screen Shot 2023-09-08 at 10 50 18 AM

error: Screen Shot 2023-09-08 at 10 50 26 AM

proposed approach: clean ? retry ? [10:50am]

first approach can be minimum viability based rather: only 'admin' string will invalidate the while block for now. get the expression working with 1 condition before extending to alternative arguments that invalidate the while block [10:52am]

frankcollins3 commented 1 year ago

just seeing: 👍 javascript: !== 👎 C# !==

👍 C#: !=

[10:54am]

frankcollins3 commented 1 year ago

👍 this works perfectly: in the below photo: dotnet run --> "User" entered into the input and the while block never executes because it's one of the three options. An argument checking for empty string is also there so the initial value doesn't validate while block statement.

dotnet run to restart console --> 👎 'friend' (! "Admin" || "Manager" || "User"] 👎 'wow' (! "Admin" || "Manager" || "User"] 👎 'sure' (! "Admin" || "Manager" || "User"]

👍 👍 👍 "User" -> 1 of the three while-block-invalidating string-values entered into the input and now while loop skip

Screen Shot 2023-09-08 at 10 56 17 AM [10:57am]

possible improvements: I feel like there's a way to do this without having 2 Console.ReadLine() statements though. [11:03am]

frankcollins3 commented 1 year ago

also, I made a wrongful assumption and chatGPT corrected it: Microsoft did not get rid of goto in C# but it is just as advised against as it apparently is/was in C++

perhaps not an improvement but a fun quirk to add, I feel there's a way to use goto to restart the console but know from C that goto can restart but not re-enter inputs, not sure if C# would be same

[11:05am]

frankcollins3 commented 1 year ago

wow goto works as expected Screen Shot 2023-09-08 at 11 16 04 AM [11:17am]