Dart Flow Control - Exercise 5

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Please make more exercise tutorial....because you explanation is great anybody who is not from programing background they also easily understand posting video Thanks

prakashanuvadia
Автор

i cant seem to access the past 3 dart exercises. are they still up?

Nabhandle
Автор

Question 2:
Suggest there’s no need to parse the console input into an integer (choice) … and that doing so either
- requires more code to catch exceptions caused by input of non-numeric input, or
- the chance of ‘uncaught exceptions’ causing a crash if such input occurs.



Leaving the input as a (single- character) String allows the switch to deal with non-allowed inputs in the default case.

jimaustin
Автор

hi could you please tell me why my cod doesn't work
void main() {
String email;
print('plz enter your email');
email = stdin.readLineSync()!;
var valid = email.contains('@') && email.contains('.');

while (valid == false) {
print('plz enter your email');
email = stdin.readLineSync()!;
var valid = email.contains('@') && email.contains('.');
}
}
and also in your answer when I use and it goes out of the loop when it only contain one of @ or . but it works well with or and i don't know

rezaEsmkhani-yz
Автор

Loop doesn't stop even when input is invalid

String menu = '''
Make your choice
1. McDonald's Fries
2. McDonald's Big Mac
3. McDonald's Breakfast Muffin
4. Exit
''';
var choice;
do {
print(menu);
var choice =
switch (choice) {
case 1:
print('McDonald\'s Fries');
print(''); // Line-Break
break;
case 2:
print('McDonald\'s Big Mac');
print(''); // Line-Break
break;
case 3:
print('McDonald\'s Breakfast Muffin');
print(''); // Line-Break
break;
case 4:
print('Have a nice day');
break;
default:
print('Invalid Choice');
}
} while (choice != 4);

itsahmed-dev
Автор

Learning a lot Thank you:

  const menu = """
\n
Please choose something from our menu:
1. McDonald's Fries
2. McDonald's Big Mac
3. McDonald's Breakfast Muffin
4. Exit
""";

  print(menu);

  int userChoice =

  while (userChoice != 4) {
    switch (userChoice) {
      case 1:
        print('You chose McDonalds Fries');
        print(menu);
        userChoice =
        break;
      case 2:
        print('You chose McDonalds Big Mac');
        print(menu);
        userChoice =
        break;
      case 3:
        print('You chose McDonalds Muffen');
        print(menu);
        userChoice =
        break;
      default:
        print('You made an invalid choice');
        print(menu);
        userChoice =
        break;
    }
  }

tertiusscheepers