Tamim
Tamim

Reputation: 181

How to print horizontally to the console in Dart?

I've been learning dart for a couple of weeks and here where I was trying to print a stack of starts (*) I discovered that there is no print method to print horizontally. It always creates a new line after it executes the print method. Here is my code:

main(List<String> args){

   for(int i = 0; i<3; i++){

      for(int k =0; k<=i; k++){
        print("*");
      }


   }

}

Here is the output:

enter image description here

Upvotes: 4

Views: 5287

Answers (1)

Danny Tuppeny
Danny Tuppeny

Reputation: 42433

You should write directly to the stdout stream:

import 'dart:io';

main() {
  stdout.write('*');
  stdout.write('*');
}

As an aside, if you want to print the same character multiple times you can multiply strings in Dart!

print('*' * 10);

will output

**********

Upvotes: 11

Related Questions