Completing C code with D style

pascal111 judas.the.messiah.111 at gmail.com
Tue Nov 2 23:45:39 UTC 2021


Next code originally was a classic C code I've written, it's pure 
vertical thinking, now, I converted it successfully to D code, 
but I think I made no much changes to make it has more horizontal 
thinking style that it seems D programmers care in horizontal 
thinking style. Is there any additions I can make in the code to 
make it suitable with D style or it's fine?

// D programming language

import std.stdio;

int main()
{


     int numbers[10]=[-3, 14, 47, -49, -30, 15, 4, -82, 99, 26];
     char negativity,
           even;

write("Would you like in list (n=negatives, p=positives, b=both)? 
");
readf(" %c", &negativity);


write("Would you like in list (e=evens, o=odds, b=both)? ");
readf(" %c", &even);


     for(int i=0; i<10; ++i)
     	{
     	 if(negativity=='n')
     	 	{
     	 	if(numbers[i]>0)
     	 		continue;
     	 	}
     	 else{
     	  if(negativity=='p')
     	  	if(numbers[i]<0)
     	  		continue;
     	  }
     	
     	  if(even=='e')
     	 	{
     	 	if(numbers[i]%2)
     	 		continue;
     	 	}
     	 else{
     	  if(even=='o')
     	  	if(!(numbers[i]%2))
     	  		continue;
     	  }		
     	 writefln("%d",numbers[i]);
     	}
     	
     	
     return 0;
     }


More information about the Digitalmars-d-learn mailing list