settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Print Lines until the command Stop

+8 votes

You will be, continuously, given input lines, until you receive the command “Stop”. Print each of those lines at the moment you read them, until you reach the ending command. Do NOT print the ending command.

Examples:

Input

Output

 

Input

Output

Line 1

Line 2

Line 3

Stop

Line 1

Line 2

Line 3

 

3

6

5

4

Stop

10

12

3

6

5

4

 

asked in JavaScript category by user mitko

1 Answer

+1 vote
 
Best answer

Here's the solution:

function printLines(args) {
  for (var i = 0; i < args.length; i++) {
    if (args[i] == "Stop") {
      break;
    }
    console.log(args[i]);
  }
}

 

answered by user nikole
selected by user golearnweb
...