Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print horizontally to the console in Dart?

Tags:

flutter

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

like image 385
Tamim Avatar asked Dec 17 '22 22:12

Tamim


1 Answers

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

**********
like image 80
Danny Tuppeny Avatar answered Feb 12 '23 21:02

Danny Tuppeny