check for new messages every one second javascript code example

Example 1: in python how to end the code after 10 input

incorrect = 0
max_tries = 3
choices = ['red', 'green', 'yellow']

while incorrect < max_tries:
    user_input = raw_input()
    if user_input not in choices:
        incorrect += 1
    else:
        rest_of_the_code(user_input)
        incorrect = 0

if incorrect == max_tries:
    sys.exit(1)

Example 2: flutter run in background every second

Timer timer;

@override
void initState() {
  super.initState();
  timer = Timer.periodic(Duration(seconds: 15), (Timer t) => checkForNewSharedLists());
}

@override
void dispose() {
  timer?.cancel();
  super.dispose();
}